Bottom Navigation Bars
Learn how to use and customize bottom navigation bars in an Android application.
Introduction
Bottom navigation bars enable switching between views with a single tap and should be used in applications with multiple top-level destinations. The recommended number of destinations for bottom navigation bars is between three and five. We’ll be using Android’s material design library by Google to add a bottom navigation bar.
Let’s jump right in and learn how to create and use a bottom navigation bar in an Android application.
Add the library dependency
To start off, make sure the material design library dependency is added in our app/build.gradle
file.
implementation 'com.google.android.material:material:1.4.0'
Note: In a local development environment, a gradle sync should be performed after adding the dependency so that the source for the library is downloaded.
Define the layout
We need to create a menu resource file containing the tab names and icons for the navigation bar. We can create a menu_bottom_navigation_bar.xml
file inside the res/menu
directory. Let’s add the following code to the menu resource file for creating a menu with four tabs.
Get hands-on with 1200+ tech skills courses.