NavigationView

** SESL Variant**. Represents a standard navigation menu for application. The menu contents can be populated by a menu resource file.

NavigationView is typically placed inside a androidx.drawerlayout.widget.DrawerLayout.

<androidx.drawerlayout.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <!-- Your contents -->

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/my_navigation_items" />
</androidx.drawerlayout.widget.DrawerLayout>

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

Constructors

Link copied to clipboard
constructor(@NonNull context: Context)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet, defStyleAttr: Int)

Types

Link copied to clipboard
Listener for handling events on navigation items.
Link copied to clipboard
User interface state that is stored by NavigationView for implementing onSaveInstanceState().

Functions

Link copied to clipboard
open fun addHeaderView(@NonNull view: View)
Adds a View as a header of the navigation menu.
Link copied to clipboard
Call this method from onBackCancelled or handleOnBackCancelled so that the back handler can cancel the back animation.
Link copied to clipboard
Returns the currently checked item in this navigation menu.
Link copied to clipboard
Get the distance between the end of a divider and the end of the NavigationView.
Link copied to clipboard
Get the distance between the start edge of the NavigationView and the start of a menu divider.
Link copied to clipboard
open fun getHeaderCount(): Int
Gets the number of headers in this NavigationView.
Link copied to clipboard
open fun getHeaderView(index: Int): View
Gets the header view at the specified position.
Link copied to clipboard
Returns the background drawable for our menu items.
Link copied to clipboard
Returns the horizontal (left and right) padding in pixels applied to menu items.
Link copied to clipboard
Returns the padding in pixels between the icon (if present) and the text of menu items.
Link copied to clipboard
Returns the tint which is applied to our menu items' icons.
Link copied to clipboard
open fun getItemMaxLines(): Int
Gets the android:maxLines attribute of the text view in the menu item.
Link copied to clipboard
Returns the tint which is applied to our menu items' icons.
Link copied to clipboard
Returns the vertical (top and bottom) padding in pixels applied to menu items.
Link copied to clipboard
open fun getMenu(): Menu
Returns the Menu instance associated with this navigation view.
Link copied to clipboard
Get the distance between the end of a menu subheader and the end of the NavigationView.
Link copied to clipboard
Get the distance between the start of the NavigationView and the start of a menu subheader.
Link copied to clipboard
Call this method from onBackInvoked or handleOnBackPressed so that the back handler can complete the back animation, or handle back without progress in certain cases.
Link copied to clipboard
Inflates a View and add it as a header of the navigation menu.
Link copied to clipboard
open fun inflateMenu(resId: Int)
Inflate a menu resource into this navigation view.
Link copied to clipboard
Whether or not the NavigationView will draw a scrim behind the window's bottom inset.
Link copied to clipboard
Whether or not the NavigationView will draw a scrim behind the window's end inset.
Link copied to clipboard
Whether or not the NavigationView will draw a scrim behind the window's start inset.
Link copied to clipboard
Whether or not the NavigationView will draw a scrim behind the window's top inset.
Link copied to clipboard
open fun removeHeaderView(@NonNull view: View)
Removes a previously-added header view.
Link copied to clipboard
Set whether or not the NavigationView should draw a scrim behind the window's bottom inset (typically the navigation bar)
Link copied to clipboard
open fun setCheckedItem(@NonNull checkedItem: MenuItem)
open fun setCheckedItem(@IdRes id: Int)
Sets the currently checked item in this navigation menu.
Link copied to clipboard
open fun setDividerInsetEnd(@Px dividerInsetEnd: Int)
Set the distance between the end of a divider and the end of the NavigationView.
Link copied to clipboard
open fun setDividerInsetStart(@Px dividerInsetStart: Int)
Set the distance between the start edge of the NavigationView and the start of a menu divider.
Link copied to clipboard
open fun setElevation(elevation: Float)
Link copied to clipboard
open fun setEndInsetScrimEnabled(enabled: Boolean)
Set whether or not the NavigationView should draw a scrim behind the window's end inset.
Link copied to clipboard
Set whether this view should always use canvas clipping to clip to its masked shape when applicable.
Link copied to clipboard
open fun setItemBackground(@Nullable itemBackground: Drawable)
Set the background of our menu items to a given resource.
Link copied to clipboard
Set the background of our menu items to the given resource.
Link copied to clipboard
Set the horizontal (left and right) padding in pixels of menu items.
Link copied to clipboard
open fun setItemHorizontalPaddingResource(@DimenRes paddingResource: Int)
Set the horizontal (left and right) padding of menu items.
Link copied to clipboard
open fun setItemIconPadding(@Dimension padding: Int)
Set the padding in pixels between the icon (if present) and the text of menu items.
Link copied to clipboard
open fun setItemIconPaddingResource(paddingResource: Int)
Set the padding between the icon (if present) and the text of menu items.
Link copied to clipboard
open fun setItemIconSize(@Dimension iconSize: Int)
Sets the size to be used for the menu item icons in pixels.
Link copied to clipboard
Set the tint which is applied to our menu items' icons.
Link copied to clipboard
open fun setItemMaxLines(itemMaxLines: Int)
Sets the android:maxLines attribute of the text view in the menu item.
Link copied to clipboard
Set the text appearance of the menu items to a given resource.
Link copied to clipboard
Sets whether the active menu item label is bold.
Link copied to clipboard
Set the text color to be used on our menu items.
Link copied to clipboard
open fun setItemVerticalPadding(@Px padding: Int)
Set the vertical (top and bottom) padding in pixels of menu items.
Link copied to clipboard
open fun setItemVerticalPaddingResource(@DimenRes paddingResource: Int)
Set the vertical (top and bottom) padding of menu items.
Link copied to clipboard
Set a listener that will be notified when a menu item is selected.
Link copied to clipboard
open fun setOverScrollMode(overScrollMode: Int)
Link copied to clipboard
Set whether or not the NavigationView should draw a scrim behind the window's start inset.
Link copied to clipboard
open fun setSubheaderInsetEnd(@Px subheaderInsetEnd: Int)
Set the distance between the end of a menu subheader and the end of the NavigationView.
Link copied to clipboard
open fun setSubheaderInsetStart(@Px subheaderInsetStart: Int)
Set the distance between the start of the NavigationView and the start of a menu subheader.
Link copied to clipboard
open fun setTopInsetScrimEnabled(enabled: Boolean)
Set whether or not the NavigationView should draw a scrim behind the window's top inset (typically the status bar).
Link copied to clipboard
Call this method from onBackStarted or handleOnBackStarted so that the back handler can initialize and start animating.
Link copied to clipboard
Call this method from onBackProgressed or handleOnBackProgressed so that the back handler can continue animating with a new progress value.