Navigation Drawer In Android With Fragments And Material Design Example

Today’s tutorial is Android Navigation Drawer With Fragments And Material Design Example.

Android Navigation Drawer with fragments example guides you to create a sliding navigation menu with recyclerview.

Android Navigation Drawer with fragments tutorial uses fragments for navigation purpose.

You may have seen some application in which, when choose different options from navigation drawer, action bar shows different icons and labels for every particular fragment.

Checkout your whatsapp, they doing exact this thing with tablayout. If you want ti implement this feature with navigation drawer, then learn how to give actionbar/toolbar each fragment of navigation drawer android.

If you are eager to know how to work with nested fragments, then read to implement nested fragment with navigation drawer android.

Visit this for more information about navigation drawer.

First, check the output and then follow all the steps.

Download Source Code For Android Navigation Drawer With Fragments tutorial

[sociallocker] Download DrawerBasicDemonuts [/sociallocker]

Step 1: Create a new project in Android Studio.

Always try to make default activity as empty activity. It will simplify the initial steps of every app.

Step 2: Update build.gradle(Module:app) file

Add below in build.gradle(Module:app) file

Final code for build.gradle(Module:app)

Step 3: Preparing two fragments

Create two fragments and give them name as “FriendListFragment” and “NotificationFragment.

Add below code in fragment_friend_list.xml

Add below code in

Copy following source code in fragment_notification.xml

Copy following code in

Step 4: Adding images

Download images and copy them into “drawable” directory.

Download icons

Step 5: Updating strings.xml and styles.xml

Update string.xml as per below code

Update styles.xml as following

Step 6: Adding toolbar.xml

Create new layout resource file and give it name as “toolbar.xml

Copy below source code in it.

Step 7: Creating lv_item.xml file

Make a new layout resource file named “lv_item.xml

This file is a recyclerview item file. Add below code in it

Step 8: Creating Model

Create a new Java class named “DrawerModel” and add following code

Step 9: Making Recyclerview Adapter

Create a new Java class named “DrawerAdapter” and paste below code

Step 10: Creating DrawerFragment

Make a new fragment named DrawerFragment.

Add below source code in fragment_drawer.xml

Add following source code into

Step 11: Description of

In onCreateView() method, recyclerview is initialized and its onClick() method is implemented.

For recyclerview’s onClick() method implementation, a class named RecycletTouchListener and an interface named ClickListener is defined.

openFragment() method will open fragment. Here, a removeAllFragment() method is used to remove all fragments from back stack and open a fresh new fragment.

setUpDrawer() method will be used in MainActivity.

Step 12: Updating MainActivity

Copy below code into activity_main.xml

Update as per following

Kotlin Version

Kotlin version of this tutorial : Navigation Drawer Kotlin Example

The End for Navigation Drawer In Android Studio example.

Comment if you have queries or want to give a review. 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 *