Skip to content

Most visited

Recently visited

navigation

BottomNavigationView

public class BottomNavigationView
extends FrameLayout

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.support.design.widget.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. It should be used when application has three to five top-level destinations.

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:
 <android.support.design.widget.BottomNavigationView
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/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>
 

Summary

Nested classes

interface BottomNavigationView.OnNavigationItemReselectedListener

Listener for handling reselection events on bottom navigation items. 

interface BottomNavigationView.OnNavigationItemSelectedListener

Listener for handling selection events on bottom navigation items. 

XML attributes

android.support.design:itemBackground  
android.support.design:itemIconTint  
android.support.design:itemTextColor  

Inherited XML attributes

From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

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

Public methods

int getItemBackgroundResource()

Returns the background resource of the menu items.

ColorStateList getItemIconTintList()

Returns the tint which is applied to our menu items' icons.

ColorStateList getItemTextColor()

Returns colors used for the different states (normal, selected, focused, etc.) of the menu item text.

int getMaxItemCount()
Menu getMenu()

Returns the Menu instance associated with this bottom navigation bar.

int getSelectedItemId()

Returns the currently selected menu item ID, or zero if there is no menu.

void inflateMenu(int resId)

Inflate a menu resource into this navigation view.

void setItemBackgroundResource(int resId)

Set the background of our menu items to the given resource.

void setItemIconTintList(ColorStateList tint)

Set the tint which is applied to our menu items' icons.

void setItemTextColor(ColorStateList textColor)

Set the colors to use for the different states (normal, selected, focused, etc.) of the menu item text.

void setOnNavigationItemReselectedListener(BottomNavigationView.OnNavigationItemReselectedListener listener)

Set a listener that will be notified when the currently selected bottom navigation item is reselected.

void setOnNavigationItemSelectedListener(BottomNavigationView.OnNavigationItemSelectedListener listener)

Set a listener that will be notified when a bottom navigation item is selected.

void setSelectedItemId(int itemId)

Set the selected menu item ID.

Protected methods

void onRestoreInstanceState(Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().

Parcelable onSaveInstanceState()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.

Inherited methods

From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML attributes

android.support.design:itemBackground

Related methods:

android.support.design:itemIconTint

Related methods:

android.support.design:itemTextColor

Related methods:

Public constructors

BottomNavigationView

added in version 25.0.0
BottomNavigationView (Context context)

Parameters
context Context

BottomNavigationView

added in version 25.0.0
BottomNavigationView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

BottomNavigationView

added in version 25.0.0
BottomNavigationView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

getItemBackgroundResource

added in version 25.0.0
int getItemBackgroundResource ()

Returns the background resource of the menu items.

Related XML Attributes:

Returns
int

See also:

getItemIconTintList

added in version 25.0.0
ColorStateList getItemIconTintList ()

Returns the tint which is applied to our menu items' icons.

Related XML Attributes:

Returns
ColorStateList

See also:

getItemTextColor

added in version 25.0.0
ColorStateList getItemTextColor ()

Returns colors used for the different states (normal, selected, focused, etc.) of the menu item text.

Related XML Attributes:

Returns
ColorStateList the ColorStateList of colors used for the different states of the menu items text.

See also:

getMaxItemCount

added in version 25.0.0
int getMaxItemCount ()

Returns
int The maximum number of items that can be shown in BottomNavigationView.

getMenu

added in version 25.0.0
Menu getMenu ()

Returns the Menu instance associated with this bottom navigation bar.

Returns
Menu

getSelectedItemId

added in version 25.3.0
int getSelectedItemId ()

Returns the currently selected menu item ID, or zero if there is no menu.

Returns
int

See also:

inflateMenu

added in version 25.0.0
void inflateMenu (int resId)

Inflate a menu resource into this navigation view.

Existing items in the menu will not be modified or removed.

Parameters
resId int: ID of a menu resource to inflate

setItemBackgroundResource

added in version 25.0.0
void setItemBackgroundResource (int resId)

Set the background of our menu items to the given resource.

Related XML Attributes:

Parameters
resId int: The identifier of the resource.

setItemIconTintList

added in version 25.0.0
void setItemIconTintList (ColorStateList tint)

Set the tint which is applied to our menu items' icons.

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply.

setItemTextColor

added in version 25.0.0
void setItemTextColor (ColorStateList textColor)

Set the colors to use for the different states (normal, selected, focused, etc.) of the menu item text.

Related XML Attributes:

Parameters
textColor ColorStateList

See also:

setOnNavigationItemReselectedListener

added in version 25.3.0
void setOnNavigationItemReselectedListener (BottomNavigationView.OnNavigationItemReselectedListener listener)

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

See also:

setOnNavigationItemSelectedListener

added in version 25.0.0
void setOnNavigationItemSelectedListener (BottomNavigationView.OnNavigationItemSelectedListener listener)

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

See also:

setSelectedItemId

added in version 25.3.0
void setSelectedItemId (int itemId)

Set the selected menu item ID. This behaves the same as tapping on an item.

Parameters
itemId int: The menu item ID. If no item has this ID, the current selection is unchanged.

See also:

Protected methods

onRestoreInstanceState

void onRestoreInstanceState (Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.

Parameters
state Parcelable: The frozen state that had previously been returned by onSaveInstanceState().

onSaveInstanceState

Parcelable onSaveInstanceState ()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.

Returns
Parcelable Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.