I have a DrawerLayout
enclosing a NavigationView
and this layout activity serves as a common Navigation drawer for all the activities in my app. I am p
In menu layout file:
In MyActivity.java - load desired menu:
public void LoadNavMenu(int iMenu){
navigationView.getMenu().clear();
navigationView.inflateMenu(iMenu);
navigationView.getMenu().setGroupVisible(R.id.HelpGroup,false);
navigationView.getMenu().setGroupVisible(R.id.SetupGroup,false);
}
And OnNavigationItemSelected:
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
navigationView.getMenu().setGroupVisible(R.id.HelpGroup,false);
navigationView.getMenu().setGroupVisible(R.id.SetupGroup,false);
switch (item.getItemId()){
case R.id.HelpGr:
navigationView.getMenu().setGroupVisible(R.id.HelpGroup,true);
navigationView.getMenu().setGroupVisible(R.id.SetupGroup,false);
return true;
case R.id.SetupGr:
navigationView.getMenu().setGroupVisible(R.id.SetupGroup,true);
navigationView.getMenu().setGroupVisible(R.id.HelpGroup,false);
return true;
}
base.closeDrawer(GravityCompat.START);
return true;
}
I have 1 item - Setup - and when user select it - I set Group with id - SetupGroup - visible and return without closing drawer. Else - I set all groups invisible.