VOOZH about

URL: https://www.geeksforgeeks.org/android/bottomnavigationview-inandroid/

⇱ BottomNavigationView in Android - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BottomNavigationView in Android

Last Updated : 15 Jul, 2025

BottomNavigationView makes it easy for users to explore and switch between top-level views with a single tap. There should be a minimum of 3 top-level views and a maximum of 5. If Destinations are more than 5 then use the Navigation Drawer. When the user taps on the icon it will change the top-level view accordingly. In a Music Player app to switch between Home, Album, and Radio, it can be used. Google plus app uses this widget to switch between different views. Instagram uses BottomNavigationView to switch between Feeds, Search, add, Like, and Profile. This is how a BottomNavigationView looks like. 

👁 Navigation-Bar


Advantages and Disadvantages of BottomNavigationView

Advantages

  • It is a Top-level destination that can be accessed from anywhere in the app.
  • It is a Material Design Component.
  • Easy to use and implement.

Disadvantages 

  • It is used only when we have only three to five Destinations.
  • Can only be used with Mobile and Tablets.
  • The length of Text Labels should be less.
  • It should be used when the user will spend more than 90% of the time in an app in the same window.
  • Using with TabLayout may cause confusion to the user.

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Note: The code for that has been given in both Java and Kotlin Programming Language for Android.


Step 2: Adding Dependency to the build.gradle.kts File

Add the support library in the build.gradle.kts (Module :app) file and add a dependency in the dependencies section. This library has the inbuilt widget for the Bottom Navigation view so through this library it can be directly added.

dependencies {
...
implementation("com.google.android.material:material:1.12.0")
}


Step 3: Create a menu for Bottom Navigation Bar

Now create a new Android Resource Directory. Right-click on the res folder and select Android Resource Directory. Make sure to select the resource type as a menu. Now create the bottom_menu.xml file and add the following code. In this file, we add the title, id, and icon of our menu for BottomNavigationView. Below is the code for the bottom_menu.xml file.

bottom_menu.xml:


Step 4: Create 3 New Fragments

Create three new fragments with the name AlgorithmFragment, CourseFragment and ProfileFragment. Create a new fragment by right click on the package name, and selecting New > Fragment > Fragment(Blank). Now add the following code in the layout files of the fragments. Here a TextView is added to the layout.


Step 5: Working with activity_main.xml

Now add the following code in the activity_main.xml file. In this file, we add BottomNavigationView to our layout.

activity_main.xml:


Step 6: Working with the MainActivity File

Go to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail. In this file, we add OnNavigationItemSelectedListener which helps to navigate between the fragments. It will switch the fragment when the user taps on the icon.

Output:

Comment

Explore