NavigationBarView

public abstract class NavigationBarView

Known direct subclasses
BottomNavigationView

Represents a standard bottom navigation bar for application.

NavigationRailView

Represents a standard navigation rail view for application.


Provides an abstract implementation of a navigation bar that can be used to implementation such as Bottom Navigation or Navigation rail.

Navigation bars make it easy for users to explore and switch between top-level views in a single tap.

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 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)

Summary

Nested types

Listener for handling reselection events on navigation items.

Listener for handling selection events on navigation items.

Constants

static final int

The active indicator width fills up the width of its parent.

static final int

The active indicator width wraps the content.

static final int

Item is placed at the center of its container

static final int

Item is placed at the start center of its container

static final int

Item is placed at the top center of its container

static final int

Icon is placed at the top of the item

static final int

Icon is placed at the top of the item

static final int

Label behaves as "labeled" when there are 3 items or less, or "selected" when there are 4 items or more.

static final int

Label is shown on all navigation items.

static final int

Label is shown on the selected navigation item.

static final int

Label is not shown on any navigation items.

Public constructors

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

Public methods

int

Get the distance between the active indicator container and the item's label.

BadgeDrawable
getBadge(int menuItemId)

Returns an instance of BadgeDrawable associated with menuItemId, null if none was initialized.

int

Returns the text appearance used for the active menu item label when they are in the horizontal item layout (when the start icon value is ITEM_ICON_GRAVITY_START).

int

Returns the text appearance used for inactive menu item labels when they are in the horizontal item layout (when the start icon value is ITEM_ICON_GRAVITY_START).

int

Get the horizontal distance between the icon and the item's label when the item is in the ITEM_ICON_GRAVITY_START configuration.

ColorStateList

Get the color of the active indicator drawable.

int

Get the height of an item's active indicator when it is expanded to wrap the item content, ie. when it is in the ITEM_ICON_GRAVITY_START configuration.

int

Get the margin that will be maintained at the start and end of the expanded active indicator away from the edges of its parent container.

int

Get the width of an item's active indicator when it is expanded to wrap the item content, ie. when it is in the ITEM_ICON_GRAVITY_START configuration.

int

Get the width of an item's active indicator.

int

Get the margin that will be maintained at the start and end of the active indicator away from the edges of its parent container.

ShapeAppearanceModel

Get the ShapeAppearanceModel of the active indicator drawable.

int

Get the width of an item's active indicator.

Drawable

Returns the background drawable of the menu items.

int

This method is deprecated.

Use getItemBackground instead.

int

Returns the navigation items' layout gravity.

int

Returns the current item icon gravity.

int

Returns the size provided for the menu item icons in pixels.

ColorStateList

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

int

Get the distance from the bottom of an item's label to the bottom of the navigation bar item.

int

Get the distance from the top of an item's icon/active indicator to the top of the navigation bar item.

ColorStateList

Returns the color used to create a ripple as the background drawable of the menu items.

int

Returns the text appearance used for the active menu item label.

int

Returns the text appearance used for inactive menu item labels.

ColorStateList

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

int
getLabelMaxLines(int labelMaxLines)

Returns the max lines limit for the label text.

int

Returns the current label visibility mode used by this NavigationBarView.

abstract int

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

Menu

Returns the Menu instance associated with this navigation bar.

ViewGroup

Returns the android.view.ViewGroup associated with the navigation bar menu.

BadgeDrawable
getOrCreateBadge(int menuItemId)

Creates an instance of BadgeDrawable associated with menuItemId if none exists.

boolean

Returns whether or not the label text should scale with the system font size.

int

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.

boolean

Get whether or not a selected item should show an active indicator.

void
removeBadge(int menuItemId)

Removes the BadgeDrawable associated with menuItemId.

void
setActiveIndicatorLabelPadding(int activeIndicatorLabelPadding)

Set the distance between the active indicator container and the item's label.

void
setElevation(float elevation)

Sets the base elevation of this view, in pixels.

void

Sets the text appearance to be used for the menu item labels when they are in the horizontal item layout (when the start icon value is ITEM_ICON_GRAVITY_START).

void

Sets the text appearance to be used for inactive menu item labels when they are in the horizontal item layout (when the start icon value is ITEM_ICON_GRAVITY_START).

void
setIconLabelHorizontalSpacing(int iconLabelSpacing)

Set the horizontal distance between the icon and the item's label when the item is in the ITEM_ICON_GRAVITY_START configuration.

void
setItemActiveIndicatorColor(ColorStateList csl)

Set the ColorStateList of the active indicator drawable.

void

Set whether a selected item should show an active indicator.

void

Set the height of an item's active indicator when it is expanded to wrap the item content, ie. when it is in the ITEM_ICON_GRAVITY_START configuration.

void

Set the horizontal margin that will be maintained at the start and end of the expanded active indicator, making sure the indicator maintains the given distance from the edge of its parent container.

void
setItemActiveIndicatorExpandedPadding(
    int paddingLeft,
    int paddingTop,
    int paddingRight,
    int paddingBottom
)

Set the padding of the expanded active indicator wrapping the content.

void

Set the width of an item's active indicator when it is expanded to wrap the item content, ie. when it is in the ITEM_ICON_GRAVITY_START configuration.

void

Set the height of an item's active indicator.

void

Set the horizontal margin that will be maintained at the start and end of the active indicator, making sure the indicator remains the given distance from the edge of its parent container.

void

Set the ShapeAppearanceModel of the active indicator drawable.

void

Set the width of an item's active indicator.

void
setItemBackground(Drawable background)

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

void

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

void
setItemGravity(int itemGravity)

Sets the navigation items' layout gravity.

void
setItemIconGravity(int itemIconGravity)

Sets the navigation items' icon gravity.

void
setItemIconSize(int iconSize)

Set the size to provide for the menu item icons.

void
setItemIconSizeRes(int iconSizeRes)

Set the size to provide for the menu item icons using a resource ID.

void
setItemIconTintList(ColorStateList tint)

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

void
setItemOnTouchListener(int menuItemId, OnTouchListener onTouchListener)

Sets an android.view.View.OnTouchListener for the item view associated with the provided menuItemId.

void
setItemPaddingBottom(int paddingBottom)

Set the distance from the bottom of an item's label to the bottom of the navigation bar item.

void
setItemPaddingTop(int paddingTop)

Set the distance from the top of an items icon/active indicator to the top of the navigation bar item.

void
setItemRippleColor(ColorStateList itemRippleColor)

Set the background of our menu items to be a ripple with the given colors.

void
setItemTextAppearanceActive(int textAppearanceRes)

Sets the text appearance to be used for the menu item labels.

void

Sets whether the active menu item labels are bold.

void
setItemTextAppearanceInactive(int textAppearanceRes)

Sets the text appearance to be used for inactive menu item labels.

void
setItemTextColor(ColorStateList textColor)

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

void
setLabelFontScalingEnabled(boolean labelFontScalingEnabled)

Sets whether or not the label text should scale with the system font size.

void
setLabelMaxLines(int labelMaxLines)

Set the max lines limit for the label text.

void
setLabelVisibilityMode(int labelVisibilityMode)

Sets the navigation items' label visibility mode.

void

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

void

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

void
setSelectedItemId(int itemId)

Set the selected menu item ID.

Protected methods

boolean

Returns whether or not submenus are supported.

void
void
onRestoreInstanceState(Parcelable state)
Parcelable

Constants

ACTIVE_INDICATOR_WIDTH_MATCH_PARENT

public static final int ACTIVE_INDICATOR_WIDTH_MATCH_PARENT = -1

The active indicator width fills up the width of its parent.

ACTIVE_INDICATOR_WIDTH_WRAP_CONTENT

public static final int ACTIVE_INDICATOR_WIDTH_WRAP_CONTENT = -2

The active indicator width wraps the content.

ITEM_GRAVITY_CENTER

public static final int ITEM_GRAVITY_CENTER

Item is placed at the center of its container

ITEM_GRAVITY_START_CENTER

public static final int ITEM_GRAVITY_START_CENTER

Item is placed at the start center of its container

ITEM_GRAVITY_TOP_CENTER

public static final int ITEM_GRAVITY_TOP_CENTER

Item is placed at the top center of its container

ITEM_ICON_GRAVITY_START

public static final int ITEM_ICON_GRAVITY_START = 1

Icon is placed at the top of the item

ITEM_ICON_GRAVITY_TOP

public static final int ITEM_ICON_GRAVITY_TOP = 0

Icon is placed at the top of the item

LABEL_VISIBILITY_AUTO

public static final int LABEL_VISIBILITY_AUTO = -1

Label behaves as "labeled" when there are 3 items or less, or "selected" when there are 4 items or more.

LABEL_VISIBILITY_LABELED

public static final int LABEL_VISIBILITY_LABELED = 1

Label is shown on all navigation items.

LABEL_VISIBILITY_SELECTED

public static final int LABEL_VISIBILITY_SELECTED = 0

Label is shown on the selected navigation item.

LABEL_VISIBILITY_UNLABELED

public static final int LABEL_VISIBILITY_UNLABELED = 2

Label is not shown on any navigation items.

Public constructors

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

Public methods

getActiveIndicatorLabelPadding

public int getActiveIndicatorLabelPadding()

Get the distance between the active indicator container and the item's label.

getBadge

public BadgeDrawable getBadge(int menuItemId)

Returns an instance of BadgeDrawable associated with menuItemId, null if none was initialized.

Parameters
int menuItemId

Id of the menu item.

Returns
BadgeDrawable

an instance of BadgeDrawable associated with menuItemId or null.

See also
getOrCreateBadge

getHorizontalItemTextAppearanceActive

public int getHorizontalItemTextAppearanceActive()

Returns the text appearance used for the active menu item label when they are in the horizontal item layout (when the start icon value is ITEM_ICON_GRAVITY_START).

Returns
int

the text appearance ID used for the active menu item label

getHorizontalItemTextAppearanceInactive

public int getHorizontalItemTextAppearanceInactive()

Returns the text appearance used for inactive menu item labels when they are in the horizontal item layout (when the start icon value is ITEM_ICON_GRAVITY_START).

Returns
int

the text appearance ID used for inactive menu item labels

getIconLabelHorizontalSpacing

public int getIconLabelHorizontalSpacing()

Get the horizontal distance between the icon and the item's label when the item is in the ITEM_ICON_GRAVITY_START configuration.

getItemActiveIndicatorColor

public ColorStateList getItemActiveIndicatorColor()

Get the color of the active indicator drawable.

Returns
ColorStateList

A ColorStateList used as the color of the active indicator.

getItemActiveIndicatorExpandedHeight

public int getItemActiveIndicatorExpandedHeight()

Get the height of an item's active indicator when it is expanded to wrap the item content, ie. when it is in the ITEM_ICON_GRAVITY_START configuration.

Returns
int

The height, in pixels, of a menu item's expanded active indicator.

getItemActiveIndicatorExpandedMarginHorizontal

public int getItemActiveIndicatorExpandedMarginHorizontal()

Get the margin that will be maintained at the start and end of the expanded active indicator away from the edges of its parent container.

Returns
int

The horizontal margin, in pixels.

getItemActiveIndicatorExpandedWidth

public int getItemActiveIndicatorExpandedWidth()

Get the width of an item's active indicator when it is expanded to wrap the item content, ie. when it is in the ITEM_ICON_GRAVITY_START configuration.

Returns
int

The width, in pixels, of a menu item's active indicator.

getItemActiveIndicatorHeight

public int getItemActiveIndicatorHeight()

Get the width of an item's active indicator.

Returns
int

The width, in pixels, of a menu item's active indicator.

getItemActiveIndicatorMarginHorizontal

public int getItemActiveIndicatorMarginHorizontal()

Get the margin that will be maintained at the start and end of the active indicator away from the edges of its parent container.

Returns
int

The horizontal margin, in pixels.

getItemActiveIndicatorShapeAppearance

public ShapeAppearanceModel getItemActiveIndicatorShapeAppearance()

Get the ShapeAppearanceModel of the active indicator drawable.

Returns
ShapeAppearanceModel

The ShapeAppearanceModel of the active indicator drawable.

getItemActiveIndicatorWidth

public int getItemActiveIndicatorWidth()

Get the width of an item's active indicator.

Returns
int

The width, in pixels, of a menu item's active indicator.

getItemBackground

public Drawable getItemBackground()

Returns the background drawable of the menu items.

ref R.styleable#BottomNavigationView_itemBackground

getItemBackgroundResource

public int getItemBackgroundResource()

Returns the background resource of the menu items.

ref R.styleable#BottomNavigationView_itemBackground

getItemGravity

public int getItemGravity()

Returns the navigation items' layout gravity.

See also
setItemGravity

getItemIconGravity

public int getItemIconGravity()

Returns the current item icon gravity.

getItemIconSize

public int getItemIconSize()

Returns the size provided for the menu item icons in pixels.

ref R.styleable#BottomNavigationView_itemIconSize

See also
setItemIconSize

getItemIconTintList

public ColorStateList getItemIconTintList()

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

ref R.styleable#BottomNavigationView_itemIconTint

getItemPaddingBottom

public int getItemPaddingBottom()

Get the distance from the bottom of an item's label to the bottom of the navigation bar item.

getItemPaddingTop

public int getItemPaddingTop()

Get the distance from the top of an item's icon/active indicator to the top of the navigation bar item.

getItemRippleColor

public ColorStateList getItemRippleColor()

Returns the color used to create a ripple as the background drawable of the menu items. If a background is set using setItemBackground, this will return null.

ref R.styleable#BottomNavigationView_itemRippleColor

getItemTextAppearanceActive

public int getItemTextAppearanceActive()

Returns the text appearance used for the active menu item label.

Returns
int

the text appearance ID used for the active menu item label

getItemTextAppearanceInactive

public int getItemTextAppearanceInactive()

Returns the text appearance used for inactive menu item labels.

Returns
int

the text appearance ID used for inactive menu item labels

getItemTextColor

public ColorStateList getItemTextColor()

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

ref R.styleable#BottomNavigationView_itemTextColor

Returns
ColorStateList

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

See also
setItemTextColor

getLabelMaxLines

public int getLabelMaxLines(int labelMaxLines)

Returns the max lines limit for the label text.

getLabelVisibilityMode

public int getLabelVisibilityMode()

Returns the current label visibility mode used by this NavigationBarView.

ref com.google.android.material.R.styleable#BottomNavigationView_labelVisibilityMode

getMaxItemCount

public abstract int getMaxItemCount()

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

getMenu

public Menu getMenu()

Returns the Menu instance associated with this navigation bar.

getMenuViewGroup

public ViewGroup getMenuViewGroup()

Returns the android.view.ViewGroup associated with the navigation bar menu.

getOrCreateBadge

public BadgeDrawable getOrCreateBadge(int menuItemId)

Creates an instance of BadgeDrawable associated with menuItemId if none exists. Initializes (if needed) and returns the associated instance of BadgeDrawable associated with menuItemId.

Parameters
int menuItemId

Id of the menu item.

Returns
BadgeDrawable

an instance of BadgeDrawable associated with menuItemId.

getScaleLabelTextWithFont

public boolean getScaleLabelTextWithFont()

Returns whether or not the label text should scale with the system font size.

getSelectedItemId

public int getSelectedItemId()

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

inflateMenu

public void inflateMenu(int resId)

Inflate a menu resource into this navigation view.

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

Parameters
int resId

ID of a menu resource to inflate

isItemActiveIndicatorEnabled

public boolean isItemActiveIndicatorEnabled()

Get whether or not a selected item should show an active indicator.

Returns
boolean

true if an active indicator will be shown when an item is selected.

removeBadge

public void removeBadge(int menuItemId)

Removes the BadgeDrawable associated with menuItemId. Do nothing if none exists. Consider changing the visibility of the BadgeDrawable if you only want to hide it temporarily.

Parameters
int menuItemId

Id of the menu item.

setActiveIndicatorLabelPadding

public void setActiveIndicatorLabelPadding(int activeIndicatorLabelPadding)

Set the distance between the active indicator container and the item's label.

setElevation

public void setElevation(float elevation)

Sets the base elevation of this view, in pixels.

ref R.styleable#BottomNavigationView_elevation

setHorizontalItemTextAppearanceActive

public void setHorizontalItemTextAppearanceActive(int textAppearanceRes)

Sets the text appearance to be used for the menu item labels when they are in the horizontal item layout (when the start icon value is ITEM_ICON_GRAVITY_START).

Parameters
int textAppearanceRes

the text appearance ID used for menu item labels

setHorizontalItemTextAppearanceInactive

public void setHorizontalItemTextAppearanceInactive(int textAppearanceRes)

Sets the text appearance to be used for inactive menu item labels when they are in the horizontal item layout (when the start icon value is ITEM_ICON_GRAVITY_START).

Parameters
int textAppearanceRes

the text appearance ID used for inactive menu item labels

setIconLabelHorizontalSpacing

public void setIconLabelHorizontalSpacing(int iconLabelSpacing)

Set the horizontal distance between the icon and the item's label when the item is in the ITEM_ICON_GRAVITY_START configuration.

setItemActiveIndicatorColor

public void setItemActiveIndicatorColor(ColorStateList csl)

Set the ColorStateList of the active indicator drawable.

Parameters
ColorStateList csl

The ColorStateList used as the color of the active indicator.

setItemActiveIndicatorEnabled

public void setItemActiveIndicatorEnabled(boolean enabled)

Set whether a selected item should show an active indicator.

Parameters
boolean enabled

true if a selected item should show an active indicator.

setItemActiveIndicatorExpandedHeight

public void setItemActiveIndicatorExpandedHeight(int height)

Set the height of an item's active indicator when it is expanded to wrap the item content, ie. when it is in the ITEM_ICON_GRAVITY_START configuration.

Parameters
int height

The height, in pixels, of the menu item's active indicator.

setItemActiveIndicatorExpandedMarginHorizontal

public void setItemActiveIndicatorExpandedMarginHorizontal(int horizontalMargin)

Set the horizontal margin that will be maintained at the start and end of the expanded active indicator, making sure the indicator maintains the given distance from the edge of its parent container.

Parameters
int horizontalMargin

The horizontal margin, in pixels.

setItemActiveIndicatorExpandedPadding

public void setItemActiveIndicatorExpandedPadding(
    int paddingLeft,
    int paddingTop,
    int paddingRight,
    int paddingBottom
)

Set the padding of the expanded active indicator wrapping the content.

Parameters
int paddingLeft

The left padding, in pixels.

int paddingTop

The top padding, in pixels.

int paddingRight

The right padding, in pixels.

int paddingBottom

The bottom padding, in pixels.

setItemActiveIndicatorExpandedWidth

public void setItemActiveIndicatorExpandedWidth(int width)

Set the width of an item's active indicator when it is expanded to wrap the item content, ie. when it is in the ITEM_ICON_GRAVITY_START configuration.

Parameters
int width

The width, in pixels, of the menu item's expanded active indicator. The width may also be set as ACTIVE_INDICATOR_WIDTH_WRAP_CONTENT or ACTIVE_INDICATOR_WIDTH_MATCH_PARENT.

setItemActiveIndicatorHeight

public void setItemActiveIndicatorHeight(int height)

Set the height of an item's active indicator.

Parameters
int height

The height, in pixels, of the menu item's active indicator.

setItemActiveIndicatorMarginHorizontal

public void setItemActiveIndicatorMarginHorizontal(int horizontalMargin)

Set the horizontal margin that will be maintained at the start and end of the active indicator, making sure the indicator remains the given distance from the edge of its parent container.

Parameters
int horizontalMargin

The horizontal margin, in pixels.

setItemActiveIndicatorShapeAppearance

public void setItemActiveIndicatorShapeAppearance(
    ShapeAppearanceModel shapeAppearance
)

Set the ShapeAppearanceModel of the active indicator drawable.

Parameters
ShapeAppearanceModel shapeAppearance

The ShapeAppearanceModel of the active indicator drawable.

setItemActiveIndicatorWidth

public void setItemActiveIndicatorWidth(int width)

Set the width of an item's active indicator.

Parameters
int width

The width, in pixels, of the menu item's active indicator.

setItemBackground

public void setItemBackground(Drawable background)

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

This will remove any ripple backgrounds created by setItemRippleColor.

ref R.styleable#BottomNavigationView_itemBackground

Parameters
Drawable background

The drawable for the background.

setItemBackgroundResource

public void setItemBackgroundResource(int resId)

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

This will remove any ripple backgrounds created by setItemRippleColor.

ref R.styleable#BottomNavigationView_itemBackground

Parameters
int resId

The identifier of the resource.

setItemGravity

public void setItemGravity(int itemGravity)

Sets the navigation items' layout gravity.

Parameters
int itemGravity

the layout android.view.Gravity of the item

See also
getItemGravity

setItemIconGravity

public void setItemIconGravity(int itemIconGravity)

Sets the navigation items' icon gravity.

Parameters
int itemIconGravity

the placement of the icon in the nav item one of ITEM_ICON_GRAVITY_TOP, or ITEM_ICON_GRAVITY_START

setItemIconSize

public void setItemIconSize(int iconSize)

Set the size to provide for the menu item icons.

For best image resolution, use an icon with the same size set in this method.

ref R.styleable#BottomNavigationView_itemIconSize

Parameters
int iconSize

the size in pixels to provide for the menu item icons

setItemIconSizeRes

public void setItemIconSizeRes(int iconSizeRes)

Set the size to provide for the menu item icons using a resource ID.

For best image resolution, use an icon with the same size set in this method.

ref R.styleable#BottomNavigationView_itemIconSize

Parameters
int iconSizeRes

the resource ID for the size to provide for the menu item icons

setItemIconTintList

public void setItemIconTintList(ColorStateList tint)

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

ref R.styleable#BottomNavigationView_itemIconTint

Parameters
ColorStateList tint

the tint to apply.

setItemOnTouchListener

public void setItemOnTouchListener(int menuItemId, OnTouchListener onTouchListener)

Sets an android.view.View.OnTouchListener for the item view associated with the provided menuItemId.

setItemPaddingBottom

public void setItemPaddingBottom(int paddingBottom)

Set the distance from the bottom of an item's label to the bottom of the navigation bar item.

setItemPaddingTop

public void setItemPaddingTop(int paddingTop)

Set the distance from the top of an items icon/active indicator to the top of the navigation bar item.

setItemRippleColor

public void setItemRippleColor(ColorStateList itemRippleColor)

Set the background of our menu items to be a ripple with the given colors.

ref R.styleable#BottomNavigationView_itemRippleColor

Parameters
ColorStateList itemRippleColor

The ColorStateList for the ripple. This will create a ripple background for menu items, replacing any background previously set by setItemBackground.

setItemTextAppearanceActive

public void setItemTextAppearanceActive(int textAppearanceRes)

Sets the text appearance to be used for the menu item labels.

Parameters
int textAppearanceRes

the text appearance ID used for menu item labels

setItemTextAppearanceActiveBoldEnabled

public void setItemTextAppearanceActiveBoldEnabled(boolean isBold)

Sets whether the active menu item labels are bold.

Parameters
boolean isBold

whether the active menu item labels are bold

setItemTextAppearanceInactive

public void setItemTextAppearanceInactive(int textAppearanceRes)

Sets the text appearance to be used for inactive menu item labels.

Parameters
int textAppearanceRes

the text appearance ID used for inactive menu item labels

setItemTextColor

public void setItemTextColor(ColorStateList textColor)

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

ref R.styleable#BottomNavigationView_itemTextColor

See also
getItemTextColor

setLabelFontScalingEnabled

public void setLabelFontScalingEnabled(boolean labelFontScalingEnabled)

Sets whether or not the label text should scale with the system font size.

setLabelMaxLines

public void setLabelMaxLines(int labelMaxLines)

Set the max lines limit for the label text.

setLabelVisibilityMode

public void setLabelVisibilityMode(int labelVisibilityMode)

Sets the navigation items' label visibility mode.

The label is either always shown, never shown, or only shown when activated. Also supports "auto" mode, which uses the item count to determine whether to show or hide the label.

ref com.google.android.material.R.styleable#NavigationBarView_labelVisibilityMode

Parameters
int labelVisibilityMode

mode which decides whether or not the label should be shown. Can be one of LABEL_VISIBILITY_AUTO, LABEL_VISIBILITY_SELECTED, LABEL_VISIBILITY_LABELED, or LABEL_VISIBILITY_UNLABELED

setOnItemReselectedListener

public void setOnItemReselectedListener(
    NavigationBarView.OnItemReselectedListener listener
)

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

Parameters
NavigationBarView.OnItemReselectedListener listener

The listener to notify

setOnItemSelectedListener

public void setOnItemSelectedListener(
    NavigationBarView.OnItemSelectedListener listener
)

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

Parameters
NavigationBarView.OnItemSelectedListener listener

The listener to notify

setSelectedItemId

public void setSelectedItemId(int itemId)

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

Parameters
int itemId

The menu item ID. If no item has this ID, the current selection is unchanged.

Protected methods

isSubMenuSupported

protected boolean isSubMenuSupported()

Returns whether or not submenus are supported.

onAttachedToWindow

protected void onAttachedToWindow()

onRestoreInstanceState

protected void onRestoreInstanceState(Parcelable state)

onSaveInstanceState

protected Parcelable onSaveInstanceState()