What i want here when i move to another Fragment
by clicking in NavigationDrawer
menu button then button should be disabled.
Because addToBackStack();
method add multiple times in their stack when click again and again. So wanted to disable it when i move to another fragment.
To disable toggle button in navigation drawer use
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
to enable use LOCK_MODE_LOCKED_OPEN
replacing LOCK_MODE_LOCKED_CLOSED
To disable drawer item click
onNavigationItemSelected
where you check (id == R.id.whatevertheitemid)
also use a Boolean to allow access as you wisheg
if (id == R.id.whatevertheitemid && isAccessGiven) { // do your task
}
Its helps me to solve this issue:
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if(id==R.id.nav_item1){ //use can write your menu item here
return false;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
Use this to disable menu item:
NavigationView navigationView;
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
Now in menu item click:
Menu menuView= navigationView.getMenu();
menuView.getItem(ID).setEnabled(false);
in kotlin:
navigation.menu.findItem(R.id.your_target_item_id).setEnabled(false)
this is work for me and disabled item in drawerToggle menu
in Java:
NavigationView navigation = (NavigationView) findViewById(R.id.navigation);
navigation.getMenu().getMenu().findItem(R.id.your_target_item_id).setEnabled(false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.