How to close the navigation box when you click on an item?

Ideally, the navigation box should be closed as soon as any element has been pressed, but it does not happen automatically. How to do it? Thank!

+60
android navigation-drawer
Oct 05 '13 at 5:56
source share
4 answers

Got it!

private DrawerLayout mDrawerLayout; mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.closeDrawers(); 

Works great.

+211
Oct 05 '13 at 7:49
source share

It worked for me -

 mDrawerLayout.closeDrawer(Gravity.START, false); 
+5
Feb 21 '18 at 3:19
source share
 closeDrawer(); // called when you want to close public void closeDrawer() { if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); } } 
0
Jun 26 '19 at 5:57
source share

On the bottom right of onNavigationItemSelected, where the switch register ends, you should fix this. mDrawerLayout.closeDrawers ();

 public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()){ } mDrawerLayout.closeDrawers(); return true; } 
0
Jul 20 '19 at 15:23
source share



All Articles