Learn how to add a Toggle Button to the Navigation Drawer

In order to add the Toggle button to your App you need to follow these steps

1. Add the following code to the Activity class


2. Override the onPostCreate method

protected void onPostCreate(Bundle savedInstanceState) {

3. Override the onConfigurationChanged method

public void onConfigurationChanged(Configuration newConfig){

4. Add following snippet to onOptionsItemSelected

return true;

Follow the Video to gain better understanding. You can refer to the source code here

Learn how to use ActionBarDrawerToggle to handle DrawerLayout events

In the last article you saw how to use DrawerLayout to create NavigationDrawer. Once you have a NavigationDrawer you may want to handle the drawer open and close events.

Like if the DrawerLayout is open you may like to display a different title and also hide some menu items.

In order to handle such events you need to create a ActionBarDrawerToggle object and assign it as a Drawer Listener.

Follow the video and refer to the Source codeĀ here