NavigationRailView

Represents a standard navigation rail view for application. It is an implementation of Material Design navigation rail..

Navigation rails make it easy for users to explore and switch between top-level views in a single tap. They should be placed at the side edge of large screen devices such as tablets, when an application has three to seven 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 navigation rail bar items. Menu items can also be used for programmatically selecting which destination is currently active. It can be done using MenuItem#setChecked(true).

A header view (such as a , logo, etc.) can be added with the app:headerLayout attribute or by using addHeaderView.

layout resource file:
<com.google.android.material.navigationrail.NavigationRailView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schema.android.com/apk/res/res-auto"
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:menu="@menu/my_navigation_items"
    app:headerLayout="@layout/my_navigation_rail_fab" />

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>

res/layout/my_navigation_rail_fab.xml:
<com.google.android.material.floatingactionbutton.FloatingActionButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/my_navigation_rail_fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/my_navigation_rail_fab_content_desc"
    app:srcCompat="@drawable/ic_add" />

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)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open fun addHeaderView(@NonNull headerView: View)
Adds the specified View if any, to appear at the top of the NavigationRailView.
open fun addHeaderView(@LayoutRes layoutRes: Int)
Adds the specified View layout resource, to appear at the top of the .
Link copied to clipboard
Get the minimum height each item in the navigation rail's menu should be.
Link copied to clipboard
open fun getMaxItemCount(): Int
Returns the maximum number of items that can be shown in NavigationBarView.
Link copied to clipboard
open fun getMenuGravity(): Int
Gets the current gravity setting for how destinations in the menu view will be grouped.
Link copied to clipboard
open fun removeHeaderView()
Removes the current header view if any, from the NavigationRailView.
Link copied to clipboard
open fun setItemMinimumHeight(@Px minHeight: Int)
Set the minimum height each item in the navigation rail's menu should use.
Link copied to clipboard
open fun setMenuGravity(gravity: Int)
Sets how destinations in the menu view will be grouped.