BottomNavigationView

public class BottomNavigationView
extends NavigationBarView

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ com.google.android.material.navigation.NavigationBarView
           ↳ com.google.android.material.bottomnavigation.BottomNavigationView


Represents a standard bottom navigation bar for application. It is an implementation of material design bottom navigation.

Bottom navigation bars make it easy for users to explore and switch between top-level views in a single tap. They should be used when an application has three to five top-level destinations.

The bar can disappear on scroll, based on HideBottomViewOnScrollBehavior, when it is placed within a CoordinatorLayout and one of the children within the CoordinatorLayout is scrolled. This behavior is only set if the layout_behavior property is set to HideBottomViewOnScrollBehavior.

The bar contents can be populated by specifying a menu resource file. Each menu item title, icon and enabled state will be used for displaying bottom navigation bar items. Menu items can also be used for programmatically selecting which destination is currently active. It can be done using MenuItem#setChecked(true)

 layout resource file:
 <com.google.android.material.bottomnavigation.BottomNavigationView
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schema.android.com/apk/res/res-auto"
     android:id="@+id/navigation"
     android:layout_width="match_parent"
     android:layout_height="56dp"
     android:layout_gravity="start"
     app:menu="@menu/my_navigation_items" />

 res/menu/my_navigation_items.xml:
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:id="@+id/action_search"
          android:title="@string/menu_search"
          android:icon="@drawable/ic_search" />
     <item android:id="@+id/action_settings"
          android:title="@string/menu_settings"
          android:icon="@drawable/ic_add" />
     <item android:id="@+id/action_navigation"
          android:title="@string/menu_navigation"
          android:icon="@drawable/ic_action_navigation_menu" />
 </menu>
 

For more information, see the component developer guidance and design guidelines.

Summary

Nested classes

interface BottomNavigationView.OnNavigationItemReselectedListener

This interface is deprecated. Use NavigationBarView.OnItemReselectedListener instead.  

interface BottomNavigationView.OnNavigationItemSelectedListener

This interface is deprecated. Use NavigationBarView.OnItemSelectedListener instead.  

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

BottomNavigationView(Context context)
BottomNavigationView(Context context, AttributeSet attrs)
BottomNavigationView(Context context, AttributeSet attrs, int defStyleAttr)
BottomNavigationView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

int getMaxItemCount()

Returns the maximum number of items that can be shown in NavigationBarView.

boolean isItemHorizontalTranslationEnabled()

Returns whether the items horizontally translate on selection when the item widths fill up the screen.

void setItemHorizontalTranslationEnabled(boolean itemHorizontalTranslationEnabled)

Sets whether the menu items horizontally translate on selection when the combined item widths fill up the screen.

void setOnNavigationItemReselectedListener(BottomNavigationView.OnNavigationItemReselectedListener listener)

This method is deprecated. Use NavigationBarView.setOnItemReselectedListener(OnItemReselectedListener) instead.

void setOnNavigationItemSelectedListener(BottomNavigationView.OnNavigationItemSelectedListener listener)

This method is deprecated. Use NavigationBarView.setOnItemSelectedListener(OnItemSelectedListener) instead.

Protected methods

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited methods

Public constructors

BottomNavigationView

public BottomNavigationView (Context context)

Parameters
context Context

BottomNavigationView

public BottomNavigationView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

BottomNavigationView

public BottomNavigationView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

BottomNavigationView

public BottomNavigationView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

getMaxItemCount

public int getMaxItemCount ()

Returns the maximum number of items that can be shown in NavigationBarView.

Returns
int

isItemHorizontalTranslationEnabled

public boolean isItemHorizontalTranslationEnabled ()

Returns whether the items horizontally translate on selection when the item widths fill up the screen.

Returns
boolean whether the menu items horizontally translate on selection

setItemHorizontalTranslationEnabled

public void setItemHorizontalTranslationEnabled (boolean itemHorizontalTranslationEnabled)

Sets whether the menu items horizontally translate on selection when the combined item widths fill up the screen.

Parameters
itemHorizontalTranslationEnabled boolean: whether the items horizontally translate on selection

setOnNavigationItemReselectedListener

public void setOnNavigationItemReselectedListener (BottomNavigationView.OnNavigationItemReselectedListener listener)

This method is deprecated.
Use NavigationBarView.setOnItemReselectedListener(OnItemReselectedListener) instead.

Set a listener that will be notified when the currently selected bottom navigation item is reselected. This does not require an BottomNavigationView.OnNavigationItemSelectedListener to be set.

Parameters
listener BottomNavigationView.OnNavigationItemReselectedListener: The listener to notify

setOnNavigationItemSelectedListener

public void setOnNavigationItemSelectedListener (BottomNavigationView.OnNavigationItemSelectedListener listener)

This method is deprecated.
Use NavigationBarView.setOnItemSelectedListener(OnItemSelectedListener) instead.

Set a listener that will be notified when a bottom navigation item is selected. This listener will also be notified when the currently selected item is reselected, unless an BottomNavigationView.OnNavigationItemReselectedListener has also been set.

Parameters
listener BottomNavigationView.OnNavigationItemSelectedListener: The listener to notify

Protected methods

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int