Double-side Nav Drawer

Hello guys, this post will teach you how to add both Left and Right Navigation Drawers in your Android App. You may need one Nav Drawer on the right to give your users a different set of options, not to distract them from the main navigation items on the left.

I have used Android Studio 1.5.1 Build 141.2456560.  So here we go.

1) Navigation Drawer Activity

     When creating a New Project, choose Navigation Drawer Activity. This makes things easy.


If this option is not available, you can the simply choose Blank Activity and later make the project structure similar to Navigation Drawer Activity. See the layout files here.

If you run the app at this point, you will see the Left Nav Drawer.

                                         

2)  Navigation Views


    As you can see I have added 2 Navigation Views inside Drawer Layout...one for left-side and other for right-side. For the Right-side, add android:layout_gravity="end"
Other thing you will notice is app:menu.The easiest way to add menu items within the NavDrawer is through XML.

3)  Drawer Menu Items

      Inside menu folder, add two XMLs --- activity_main_drawer.xml (for left-drawer) and activity_right_drawer.xml (for right-drawer).


4) Icon to open Right-Drawer

To the main.xml file which shows Settings in an overflow menu on the top-right, make these changes. You can add any icon of your choice.

5) Navigation Item Selected Listeners


The only important line to notice is drawer.closeDrawer(GravityCompat.END); for the Right NavDrawer. Otherwise the code is simple,well-commented and easy to implement.

                           

                           

                                               The complete code is here

Comments

Popular posts from this blog

Quotographics

LiFi :The next gen WiFi