The Navigation Drawer slides in from the left and contains the navigation destinations for our app. While creating the android application if we select Navigation Drawer Activity, automatically the navigation drawer menu will be created with all required sliding menu options.
Now we will see how to create navigation drawer sliding menu using Navigation Drawer Activity in android application with example.
Following is the example of creating navigation drawer sliding menu in the android application.
Create a new android application using android studio and give names as NavigationDrawerExample like as shown below.
Now we need to select the form factors which we need for our app. In case if you're not sure what you need, just select Phone and Tablet and then click Next like as shown below.
Now select the Navigation Drawer Activity in 'Add an activity to Mobile' dialog and click Next like as shown below.
Customize the activity by entering activity name, layout name and title as prompted. In case if default values are fine, then click Finish like as shown below.
Once the project created, automatically all the required details will be added in a project to create the navigation drawer sliding menu like as shown below.
If you observe the above project structure, the android studio automatically created all the required files to create navigation drawer sliding menu.
Now open activity_main.xml file from \res\layout folder path and it will contain the code like as shown below.
<?xml version="1.0" encoding="utf-8"?>
Now open your main activity file MainActivity.java from \java\com.tutlane.audioplayerexample path and write the code like as shown below
If you want to modify the default navigation drawer sliding menu, then you need to customize the code based on your requirements.
When we run the above program in the android studio we will get the result as shown below.
If you observe the above result, the Navigation Drawer slides in from the left and contains the navigation destinations for our app. We can customize the navigation drawer by changing the default things based on our requirements.
This is how we can implement the navigation drawer sliding menu in android applications based on our requirements.