Open In App

How to Add a Floating Action Button to Bottom Navigation Bar in Android?

Last Updated : 19 Feb, 2021
Like Article

The floating action button is a bit different button from the ordinary buttons. Floating action buttons are implemented in the app’s UI for primary actions (promoted actions) for the users and the actions under the floating action button are prioritized by the developer. For example the actions like adding an item to the existing list. Bottom navigation bars allow movement between primary destinations in an app. Some popular examples include Instagram, WhatsApp, etc. In this article, we will learn how to add a Floating Action Button (FAB) in the middle of the Bottom Navigation bar in android. A sample image is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Kotlin language. 

How to Add a Floating Action Button to Bottom Navigation Bar in Android?

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.

Step 2: Add dependency to the build.gradle file

Inside build.gradle(app) add Material Design Dependency.

implementation ‘’

After adding the material design dependency click on the Sync now.

Step 3: Change the theme of the app to Material Components

Below is the code for the styles.xml file.


    <!-- Base application theme. -->
    <style name="Theme.Fab_Bottom_app_bar" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <item name="colorPrimary">#0F9D58</item>
        <item name="colorPrimaryVariant">#0F9D58</item>
        <item name="colorOnPrimary">#000</item>

Step 4: Import Icons from Vector assets

Go to res > drawable (right-click) > new -> vector assets and import five icons from there namely Home, Search, Person, Add, Settings. And your project structure should look like this after this step.

Step 5: Create menu items that have to be shown in the bottom navigation view

Go to res (right-click) > New > Android resource file and in the pop-up menu choose the resource type to menu and name the file bottom_nav_menu. It should look like this.

Inside bottom_nav_menu.xml add items that we want to show in the bottom app bar. Below is the code for the bottom_nav_menu.xml file.


<?xml version="1.0" encoding="utf-8"?>
        android:title="Home" />
        android:title="Search" />
        android:title="" />
        android:title="Profile" />
        android:title="Settings" />

Step 6: Working with the AndroidManifest.xml file

Change the theme inside the AndroidManifest.xml file. Below is the code for the AndroidManifest.xml file.


<?xml version="1.0" encoding="utf-8"?>
        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

Step 7: Working with the activity_main.xml file

  • Change the root layout to Coordinator Layout
  • Add Bottom App bar.
  • Inside the Bottom app, the bar adds the bottom Navigation View and adds the menu items that we created in the last step.
  • Add the Floating action button.

Below is the code for the activity_main.xml file.


<?xml version="1.0" encoding="utf-8"?>
            app:menu="@menu/bottom_nav_menu" />
        app:layout_anchor="@id/bottomAppBar" />

Step 8: Working with the MainActivity.kt file

Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file.


import android.os.Bundle
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        bottomNavigationView.background = null = false


Floating Action Button to Bottom Navigation Bar

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads