Android Navigation Drawer + Fragment Tutorial

Android Navigation Drawer is a advance form that display the main menu option in the left or right edge screen for navigate to another page.  It is always not visible in the screen, user can swipe right or left to make the Navigation Drawer visible in the screen. Fragment are the good combination with the Navigation Drawer, it make the Navigation Drawer carry more activity and improve the performance. In this tutorial, I will teach u on how to use Navigation Drawer in the Android Studio.

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “NavigationDExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Navigation Drawer Activity” and Click Next button
5. Lastly, press finish button.

After that, it will automatically create 4 layouts in your res > layout package. The 3 layouts are activity.main.xml, app_bar_main.xml , content_main.xml and nav_header_main.xml.

activity_main.xml

app_bar_main.xml

content_main.xml

nav_header_main.xml

Create Fragments Activity

Add 2 new fragment activity and integrate into navigation drawer by right click > new > Fragment (Blank). First fragment activity name as “ND1Fragment”, the second fragment name as “ND2Fragment”.

Edit fragment_nd1.xml and fragment_nd2.xml layout

Go to layout package and edit your fragment_first.xml to the following code.

After that, also edit your fragment_nd2.xml to the following code.

Edit ND1Fragment.java and ND2Fragment.java classes

Go to modify your nd1fragment.java to the following code.

After that, also modify your nd2fragment.java to the following code.

Edit MainActivity.java class

Last, go to your MainActivity.java and add the following code. This activity will add 2 fragments into the navigation drawer.

Run your Project

Now you can start your project in your android device or emulator. It just very easy to use navigation drawer in android application.

(Android Navigation Drawer)

Source Code

(Visited 3,597 times, 1 visits today)
Advertisements

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

3 Responses

  1. ramsan says:

    please check download file is wrong.

  2. I have noticed you don’t monetize your website, don’t waste your traffic, you can earn additional cash every month.
    You can use the best adsense alternative for any type of website (they approve
    all websites), for more details simply search in gooogle: boorfe’s tips monetize your website

  1. November 27, 2016

    […] menu to let the user to navigate different activity. Android Sliding pane is the older version of Navigation Drawer before material design is coming out and it is slightly different which it does not overlay the […]

Leave a Reply

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