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
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
open fun collapse()
Collapse the navigation rail.
Link copied to clipboard
open fun expand()
Expand the navigation rail.
Link copied to clipboard
Gets the minimum height of a navigation rail menu item when the navigation rail is collapsed.
Link copied to clipboard
Link copied to clipboard
Gets the minimum height of a navigation rail menu item when the navigation rail is expanded.
Link copied to clipboard
open fun getItemGravity(): Int
Returns the navigation items' layout gravity.
Link copied to clipboard
Returns the current item icon gravity.
Link copied to clipboard
Get the current minimum height each item in the navigation rail's menu should be.
Link copied to clipboard
open fun getItemSpacing(): Int
Get the current padding in between the navigation rail menu items.
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 isExpanded(): Boolean
Returns whether or not the navigation rail is currently expanded.
Link copied to clipboard
Link copied to clipboard
open fun removeHeaderView()
Removes the current header view if any, from the NavigationRailView.
Link copied to clipboard
open fun setCollapsedItemMinimumHeight(@Px minHeight: Int)
Sets the minimum height of a navigation rail menu item when the navigation rail is collapsed.
Link copied to clipboard
open fun setCollapsedItemSpacing(@Px itemSpacing: Int)
Sets the padding in between the navigation rail menu items when the navigation rail is collapsed.
Link copied to clipboard
open fun setExpandedItemMinimumHeight(@Px minHeight: Int)
Sets the minimum height of a navigation rail menu item when the navigation rail is expanded.
Link copied to clipboard
open fun setItemGravity(itemGravity: Int)
Sets the navigation items' layout gravity.
Link copied to clipboard
open fun setItemIconGravity(itemIconGravity: Int)
Sets the navigation items' icon gravity.
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 setItemSpacing(@Px itemSpacing: Int)
Set the padding in between the navigation rail menu items.
Link copied to clipboard
open fun setMenuGravity(gravity: Int)
Sets how destinations in the menu view will be grouped.
Link copied to clipboard