【发布时间】:2020-07-27 01:41:30
【问题描述】:
我已经使用 android studio 模板(导航抽屉活动)创建了一个导航抽屉活动。现在在 androidx & android studio 3.5.3 他们已经改变了导航抽屉活动的实现。在java类中的实现看起来像
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow,
R.id.nav_tools, R.id.nav_share, R.id.nav_send)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
而onCreateOptionsMenu 采用ContextMenu、View 和ContextMenu.ContextMenuInfo 而不仅仅是Menu
@Override
public void onCreateOptionsMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.nav_drawer_main, menu);
}
但是没有onOptionsItemSelected 或onContextItemSelected 方法。所以我的问题是如果我想自定义抽屉项点击事件,我该怎么做?假设我想将 intentExtra 传递给片段,或者我必须检查特定项目点击的变量值。
提前致谢。
【问题讨论】:
标签: android android-studio android-fragments navigation-drawer