Ideally navigation drawer should get closed once some item has been pressed from it, but its not happening automatically. How to do it ? Thanks!
Use closeDrawer() method to close the drawer and start your other activity on the listener of 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.
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.
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.
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.
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.
Got it!
private DrawerLayout mDrawerLayout; mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.closeDrawers();
Working perfectly fine.
For me this one worked -
mDrawerLayout.closeDrawer(Gravity.START, false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With