Navigation View
** 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>
Content copied to clipboard
For more information, see the component developer guidance and design guidelines.
Types
Link copied to clipboard
interface OnNavigationItemSelectedListener
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
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
Gets the number of headers in this NavigationView.
Link copied to clipboard
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
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
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
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
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
Sets the currently checked item in this navigation menu.
Link copied to clipboard
Set the distance between the end of a divider and the end of the NavigationView.
Link copied to clipboard
Set the distance between the start edge of the NavigationView and the start of a menu divider.
Link copied to clipboard
Link copied to clipboard
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
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
Set the horizontal (left and right) padding of menu items.
Link copied to clipboard
Set the padding in pixels between the icon (if present) and the text of menu items.
Link copied to clipboard
Set the padding between the icon (if present) and the text of menu items.
Link copied to clipboard
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
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
Set the vertical (top and bottom) padding in pixels of menu items.
Link copied to clipboard
Set the vertical (top and bottom) padding of menu items.
Link copied to clipboard
open fun setNavigationItemSelectedListener(@Nullable listener: NavigationView.OnNavigationItemSelectedListener)
Set a listener that will be notified when a menu item is selected.
Link copied to clipboard
Link copied to clipboard
Set whether or not the NavigationView should draw a scrim behind the window's start inset.
Link copied to clipboard
Set the distance between the end of a menu subheader and the end of the NavigationView.
Link copied to clipboard
Set the distance between the start of the NavigationView and the start of a menu subheader.
Link copied to clipboard
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.