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
there is a trick to do this without using ExpandableListView.Add those menu items normally in menu layout file and hide/show them on item click of menu item under which you want to show them like this:
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
NavigationView nv= (NavigationView) findViewById(R.id.nav_view);
Menu m=nv.getMenu();
int id = item.getItemId();
if (id == R.id.nav_posts) {
boolean b=!m.findItem(R.id.nav_class).isVisible();
//setting submenus visible state
m.findItem(R.id.nav_class).setVisible(b);
m.findItem(R.id.nav_dept).setVisible(b);
m.findItem(R.id.nav_batch).setVisible(b);
m.findItem(R.id.nav_campus).setVisible(b);
return true;
} else if (id == R.id.nav_walls) {
boolean b=!m.findItem(R.id.nav_wall_events).isVisible();
//setting submenus visible state
m.findItem(R.id.nav_wall_events).setVisible(b);
m.findItem(R.id.nav_wall_fun).setVisible(b);
m.findItem(R.id.nav_wall_hadith).setVisible(b);
m.findItem(R.id.nav_wall_news).setVisible(b);
m.findItem(R.id.nav_wall_Poetry).setVisible(b);
return true;
} else if (id == R.id.nav_com) {
m.findItem(R.id.nav_share).setVisible(false);
m.findItem(R.id.nav_send).setVisible(false);
} 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;
}
where menu layout file is: