Android Navigation Drawer With Toolbar/Actionbar Menu Items

Android navigation drawer will add menu items in toolbar or action bar or header bar.

Android navigation drawer example guides to show different menu items in the toolbar for a different fragment.

This Navigation drawer Android example is the second part of basic navigation drawer in Android tutorial.

Complete all the steps from that example, then follow steps of this tutorial.

Visit the official link for more information about navigation drawer.

First, watch the output of Android navigation drawer example, then we will prepare it.

Download Source Code For Android Navigation Drawer tutorial

[sociallocker]Download DrawerMenuDemonuts[/sociallocker]

Step 1: Follow all the steps from basic navigation drawer in Android tutorial.

After you have completed above tutorial, you will have one android project with navigation drawer.

This step is must so make sure you have complete working project made from above tutorial.

Now follow below steps.

Step 2: Adding images to drawable

Download images and copy them into “drawable” directory.

Download message_icon

Step 3: Creating menu resource directory

Create a new resource directory named “menu” inside the “res” directory as per below image.

android navigation drawer

Inside “menu,” make two xml files and name them as friend_menu.xml and notification_menu.xml

Add below source code in friend_menu.xml

Copy following in notification_menu.xml

Step 4: Updating FriendListFragment

Update as below

Step 5: Describing update

In onCreate() method, setHasOptionsMenu() is called.

This method is necessary for implementing menu items in Toolbar.

This method must be present in the every fragments for which you want options in actionbar.

Two methods are override. One is onCreateOptionsMenu() and second is onOptionsItemSelected()

Step 6: Updating NotificationFragment

Replace source code of NotificationFragment with following

This small demo is the base for every application for all your future applications in which you want different menu items in toolbar or action bar for each fragments.

You also have access to onclick method of every items of toolbar. You can put logic in this onclick method.

Use comment section for your queries and reviews. Thank you 🙂

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *