A blog for technology, SEO tips, website development and open source programming.

Android Navigation Drawer Example

4 2,558

In this tutorial we’ll implement a Navigation Drawer in our android application. Android navigation drawer is a sliding menu and it’s an important UI component. You will see navigation drawer in most of the android applications, it’s like navigation menu bars in the websites.

Follow me on Instagram


Adding Navigation Drawer Activity

If you want to add Navigation Drawer Activity to your existing project you can simply add it by going to your package -> right click -> new -> activity -> navigation drawer activity

Android-Navigation-Drawer-Activity

android-navigation-drawer-example

This is the simplest way for creating a navigation drawer activity.




Navigation Drawer Menus

To change the menu open the activity_main_drawer.xml inside menu folder.

This is my activity_main_drawer.xml

Try changing the values and run.

 device-screenshot

Handling Events

Open you activity which has the Drawer in it. It will contain a method like this.

[alert type=blue ]

Don’t miss

Android start activity once notification clicked

[/alert]

Changing Screens using Fragments for each MenuItem

For Simplicity, I am creating a Fragment for all the Menu Items which has a layout with only a TextView.


Layout Change

We will add a FrameLayout inside the content_home.xml for adding and replacing Fragments.

MenuFragment

Adding Screens for each Menu

Display First Screen

To Display the first screen we will add the first fragment in the onCreate of the Activity.

[alert type=white ]All Done. Check out the source code on my github account[/alert]

Please send your valuable comments below regarding the post.

Tweets on Twitter


Code on Github

Subscribe to my Youtube Channel

4 Comments
  1. […] Android Navigation Drawer Example […]

  2. […] Android Navigation Drawer Example […]

  3. […] Android Navigation Drawer Example […]

  4. […] Android Navigation Drawer Example […]

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More