这里我使用了android studio提供的基本导航 View
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.getMenu().getItem(1).setChecked(true);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
/* // Handle navigation view item clicks here.
int id = item.getItemId();*/
//Check and un-check menu item if they are checkable behaviour
switch (item.getItemId()) {
case R.id.nav_camera: {
Intent intent = new Intent(MainActivity.this, TabbedActivity.class);
startActivity(intent);
break;
}
case R.id.nav_gallery: {
Toast.makeText(getApplicationContext(), "youclicked", Toast.LENGTH_SHORT).show();
break;
}
/* else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}*/
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
});
即使我正在检查第二个项目,它也在响应点击如何停止 请帮助我,我从昨天开始就面临这个问题
最佳答案
您可以在 onPrepareOptionsMenu(Menu menu) 中执行此操作
@Override
public boolean onPrepareOptionsMenu (Menu menu){
super.onPrepareOptionsMenu(menu);
MenuItem myItem = menu.findItem(R.id.myId); //here your menu ids
myItem.setEnabled(false);
return true;
}
Prepare the Screen's standard options menu to be displayed. This is called right before the menu is shown, every time it is shown. You can use this method to efficiently enable/disable items or otherwise dynamically modify the contents.
关于android - 如何停止在多个 Activity 中使用的抽屉导航 Activity 中选中项目的点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48700358/