Steps to Implement Navigation Drawer in Android
Step 1: Create a New Android Studio Project
Create an empty activity android studio project. Refer to Android | How to Create/Start a New Project in Android Studio? on how to create an empty activity android studio project.
Step 2: Adding a dependency to the project
In this discussion, we are going to use the Material Design Navigation drawer. So add the following Material design dependency to the app-level Gradle file.
implementation 'com.google.android.material:material:1.3.0-alpha03'
Refer to the following image if unable to locate the app-level Gradle file that invokes the dependency (under project hierarchy view). After invoking the dependency click on the “Sync Now” button. Make sure the system is connected to the network so that Android Studio downloads the required files.
Step 3: Creating a menu in the menu folder
Create the menu folder under the res folder. To implement the menu. Refer to the following video to create the layout to implement the menu.
Invoke the following code in the navigation_menu.xml
- XML
Step 4: Working with the activity_main.xml File
Invoke the following code in the activity_main.xml to set up the basic things required for the Navigation Drawer.
- XML
Output UI:

One thing to be noticed is that the menu drawer icon is still not appeared on the action bar. We need to set the icon and its open-close functionality programmatically.
Step 5: Include the Open Close strings in the string.xml
Invoke the following code in the app/res/values/strings.xml file.
- XML
Step 6: Working with the MainActivity File
- Invoke the following code in the MainActivity file to show the menu icon on the action bar and implement the open-close functionality of the navigation drawer.
- Comments are added inside the code for better understanding.
- Java
- Kotlin
Output: Run on Emulator
Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Post a Comment