Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close navigation drawer when an item is pressed from it?

Ideally navigation drawer should get closed once some item has been pressed from it, but its not happening automatically. How to do it ? Thanks!

like image 533
Vipul J Avatar asked Oct 05 '13 05:10

Vipul J


People also ask

Which piece of code is used to close the navigation drawer?

Use closeDrawer() method to close the drawer and start your other activity on the listener of drawer.

How do I customize my navigation drawer?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/nav_header_main.

How do I open and close a navigation drawer?

A standard dismissible navigation drawer is opened and closed by tapping the navigation menu icon in the top app bar (1), and remains open until the menu icon is tapped again (2). A standard navigation drawer can use one of these elevation positions: A full-height navigation drawer is at the same elevation as a top app bar.

What is the navigation drawer and how to use it?

The navigation drawer slides in from the left and contains the navigation destinations for the app. The user can view the navigation drawer when the user swipes a finger from the left edge of the activity. They can also find it from the home activity by tapping the app icon in the action bar.

How to jump to an existing route in the drawer navigator?

The closeDrawer action can be used to close the drawer pane. The toggleDrawer action can be used to open the drawer pane if closed, or close if open. The jumpTo action can be used to jump to an existing route in the drawer navigator. name - string - Name of the route to jump to. params - object - Screen params to pass to the destination route.

What is the use of closedrawer and toggledrawer?

The closeDrawer action can be used to close the drawer pane. The toggleDrawer action can be used to open the drawer pane if closed, or close if open. The jumpTo action can be used to jump to an existing route in the drawer navigator.


2 Answers

Got it!

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

Working perfectly fine.

like image 84
Vipul J Avatar answered Sep 23 '22 08:09

Vipul J


For me this one worked -

mDrawerLayout.closeDrawer(Gravity.START, false); 
like image 31
Anirban Avatar answered Sep 23 '22 08:09

Anirban