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>

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
Returns the currently checked item in this navigation menu.
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
open fun getMenu(): Menu
Returns the Menu instance associated with this navigation view.
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
open fun removeHeaderView(@NonNull view: View)
Removes a previously-added header view.
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 setElevation(elevation: Float)
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
Set the text color to be used on our 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)