# Navigation drawer
[Navigation drawers](https://material.io/components/navigation-drawer) provide
access to destinations in your app.

**Contents**
* [Design & API Documentation](#design-api-documentation)
* [Using navigation drawers](#using-navigation-drawers)
* [Anatomy](#anatomy)
* [Standard navigation drawer](#standard-navigation-drawer)
* [Modal navigation drawer](#modal-navigation-drawer)
* [Bottom navigation drawer](#bottom-navigation-drawer)
* [Predictive Back](#predictive-back)
* [Theming](#theming)
## Design & API Documentation
* [Google Material3 Spec](https://material.io/components/navigation-drawer/overview)
* [API reference](https://developer.android.com/reference/com/google/android/material/navigation/package-summary)
## Using navigation drawers
Before you can use navigation drawers, you need to add a dependency to the
Material Components for Android library. For more information, go to the
[getting started](https://github.com/material-components/material-components-android/tree/master/docs/getting-started.md)
page. For modal navigation drawers you also need to add a dependency to the
AndroidX `DrawerLayout` library. For more information go to the
[releases](https://developer.android.com/jetpack/androidx/releases/drawerlayout)
page.
The content of all navigation drawer types can be implemented using a
`NavigationView`.
```xml
```
**Note:** The `layout_width` and `layout_height` attributes should be set to
`wrap_content`, `match_parent`, or a custom dimension depending on the
navigation drawer type and parent `ViewGroup`.
### Adding a menu

In the layout:
```xml
```
In `res/menu/navigation_drawer.xml`:
```xml
```
### Adding a header

In the layout:
```xml
```
In `res/layout/header_navigation_drawer.xml`:
```xml
```
### Adding dividers and subtitles

Dividers are automatically added between `- ` groups with unique IDs or
``s with unique IDs. When a sub-`` is added to an item it is
treated as a subtitle.
In `res/menu/navigation_drawer.xml`:
```xml
-
-
```
### Making navigation drawers accessible
Navigation drawers support content labeling for accessibility and are readable
by most screen readers, such as TalkBack. Text rendered in menu items is
automatically provided to accessibility services. Additional content labels are
optional but recommended.
For more information on content labels, go to the
[Android accessibility help guide](https://support.google.com/accessibility/android/answer/7158690).
#### Content descriptions
A content description can be set on `- `s in the `NavigationView` menu so
that screen readers like TalkBack are able to announce their purpose or action.
This can be done in XML using the `android:contentDescription` attribute or
programmatically with
`navigationView.menu.findItem(R.id.itemId)#setContentDescription` (on API 26 and
above).
Any `ImageView`s within the header layout should also have a content description
set.
#### Opening and closing navigation drawers
To open navigation drawers, use clickable widgets that meet the minimum touch
target size of `48dp` and are properly labeled for accessibility. To close
navigation drawers, consider doing the same but bear in mind that clicking on
menu items or an optional scrim should also serve this purpose.
### Using navigation drawers with the Navigation component
Navigation drawers can be used with the AndroidX Navigation library. For more
information, go to the
[documentation](https://developer.android.com/guide/navigation/navigation-ui#add_a_navigation_drawer).
## Anatomy
Navigation drawers have a container, an optional header, optional dividers,
items with inactive text, active text, and an active text overlay, optional
subtitles, and an optional scrim.

1. Container
2. Subheader (optional)
3. Label text
4. Icon (optional)
5. Active indicator/Item shape
6. Badge text (coming soon)
7. Divider
8. Scrim (modal drawer only)
### Container attributes
Element | Attribute(s) | Related method(s) | Default value
----------------------- | ------------------------------------------------------------------- | ------------------------------------------------ | -------------
**Color** | `android:background` | `setBackground`
`getBackground` | `?attr/colorSurfaceContainerLow`
**Shape** | `app:shapeAppearance`
`app:shapeAppearanceOverlay` | N/A | `null`
**Elevation** | `app:elevation` (can be used on `NavigationView` or `DrawerLayout`) | `setElevation`
`getElevation` | `0dp` (`NavigationView`) or `1dp` (`DrawerLayout`)
**Max width** | `android:maxWidth` | N/A | `280dp`
**Fits system windows** | `android:fitsSystemWindows` | `setFitsSystemWindows`
`getFitsSystemWindows` | `true`
**Drawer corner size** | `drawerLayoutCornerSize` | N/A | `16dp`
### Header attributes
Element | Attribute | Related method(s) | Default value
---------- | ------------------ | --------------------------------------------------------------------------------------------------- | -------------
**Layout** | `app:headerLayout` | `addHeaderView`
`inflateHeaderView`
`getHeaderView`
`getHeaderCount`
`removeHeaderView` | `null`
### Divider attributes
Element | Attribute | Related method(s) | Default value
----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | -------------
**Divider** | `android:listDivider` in app theme | N/A | Varies per platform version
**Height** | N/A (see [layout](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/internal/res/layout/design_navigation_item_separator.xml)) | N/A | `1dp`
**Inset** | `app:dividerInsetStart`
`app:dividerInsetEnd` | `setDividerInsetStart`
`getDividerInsetStart`
`setDividerInsetEnd`
`getDividerInsetEnd` | `28dp`
`28dp`
### Item attributes
Element | Attribute(s) | Related method(s) | Default value
---------------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | -------------
**Color** | `app:itemShapeFillColor` | N/A | `?attr/colorSecondaryContainer`
**Shape** | `app:itemShapeAppearance`
`app:itemShapeAppearanceOverlay` | N/A | `@style/ShapeAppearance.Material3.Corner.Full`
(`?attr/shapeCornerFamily` and corner size `50%`)
**Insets** | `app:itemShapeInsetStart`
`app:itemShapeInsetTop`
`app:itemShapeInsetEnd`
`app:itemShapeInsetBottom` | N/A | `12dp`
`0dp`
`12dp`
`0dp`
**Horizontal padding** | `app:itemHorizontalPadding` | `setItemHorizontalPadding`
`setItemHorizontalPaddingResource`
`getItemHorizontalPadding` | `28dp`
**Vertical padding** | `app:itemVerticalPadding` | `setItemVerticalPadding`
`setItemVerticalPaddingResource`
`getItemVerticalPadding` | `4dp`
### Text attributes
| Element | Attribute | Related method(s) | Default value |
|-------------------------|-------------------------------------------|------------------------------------------|----------------------------------------------------------------------------------|
| **Color** | `app:itemTextColor` | `setItemTextColor`
`getItemTextColor` | `?attr/colorOnSecondaryContainer` when active else `?attr/colorOnSurfaceVariant` |
| **Typography** | `app:itemTextAppearance` | `setItemTextAppearance` | `?attr/textAppearanceLabelLarge` |
| **Typography (active)** | `app:itemTextAppearanceActiveBoldEnabled` | `setItemTextAppearanceActiveBoldEnabled` | `true` |
| **Max lines** | `app:itemMaxLines` | `setItemMaxLines`
`getItemMaxLines` | `1` |
### Icon attributes
Element | Attribute | Related method(s) | Default value
----------- | --------------------- | ---------------------------------------------------------------------------- | -------------
**Color** | `app:itemIconTint` | `setIconItemTintList`
`getIconItemTintList` | `?attr/colorOnSecondaryContainer` when active else `?attr/colorOnSurfaceVariant`
**Size** | `app:itemIconSize` | `setItemIconSize` | `24dp`
**Padding** | `app:itemIconPadding` | `setItemIconPadding`
`setItemIconPaddingResource`
`getItemIconPadding` | `12dp`
### Subtitle attributes
Element | Attribute | Related method(s) | Default value
-------------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | -------------
**Color** | `app:subheaderColor` | N/A | `?attr/colorOnSurfaceVariant`
**Typography** | `app:subheaderTextAppearance` | N/A | `?attr/textAppearanceTitleSmall`
**Max lines** | N/A | N/A | `1`
**Height** | N/A | N/A | `?attr/listPreferredItemHeightSmall`
**Padding** | `app:subheaderInsetStart`
`app:subheaderInsetEnd` | `setSubheaderInsetStart`
`getSubheaderInsetStart`
`setSubheaderInsetEnd`
`getSubheaderInsetEnd` | `28dp` and `28dp`
### Scrim attributes
Element | Attribute | Related method(s) | Default value
--------- | --------- | --------------------------------- | --------------------
**Color** | N/A | `setScrimColor` on `DrawerLayout` | Black at 60% opacity
### `NavigationView` styles
Element | Style
----------------- | ---------------------------------
**Default style** | `Widget.Material3.NavigationView`
Default style theme attribute: `?attr/navigationViewStyle`
### `DrawerLayout` styles
Element | Style
----------------- | ---------------------------------
**Default style** | `Widget.Material3.DrawerLayout`
Default style theme attribute: `?attr/drawerLayoutStyle`
### Types
There are three types of navigation drawers: 1\.
[Standard navigation drawer](#standard-navigation-drawer), 2\.
[Modal navigation drawer](#modal-navigation-drawer), 3\.
[Bottom navigation drawer](#bottom-navigation-drawer)
## Standard navigation drawer
[Standard navigation drawers](https://material.io/components/navigation-drawer#standard-drawer)
allow interaction with both screen content and the drawer at the same time. They
can be used on tablet and desktop, but they aren’t suitable for mobile devices
due to limited screen size.
API and source code:
* `NavigationView`
* [Class definition](https://developer.android.com/reference/com/google/android/material/navigation/NavigationView)
* [Class source](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/NavigationView.java)
### Standard navigation drawer example
The following example shows a permanently visible standard navigation drawer.

In the layout:
```xml
```
In `res/values/themes.xml`:
```xml
```
In `res/layout/header_navigation_drawer.xml`:
```xml
...
```
## Modal navigation drawer
[Modal navigation drawers](https://material.io/components/navigation-drawer#modal-drawer)
block interaction with the rest of an app’s content with a scrim. They are
elevated above most of the app’s UI and don’t affect the screen’s layout grid.
They are primarily used for mobile devices where screen space is limited, and
can be replaced by standard drawers on tablet and desktop.
[DrawerLayout](https://developer.android.com/reference/androidx/drawerlayout/widget/DrawerLayout)
is used in conjunction with NavigationDrawer to achieve the modal navigation
drawer.
API and source code:
* `NavigationView`
* [Class definition](https://developer.android.com/reference/com/google/android/material/navigation/NavigationView)
* [Class source](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/NavigationView.java)
* `DrawerLayout`
* [Class definition](https://developer.android.com/reference/androidx/drawerlayout/widget/DrawerLayout)
### Modal navigation drawer example
The following example shows a modal navigation drawer.

In the layout:
```xml
```
In `res/values/themes.xml`:
```xml
```
In `res/layout/header_navigation_drawer.xml`:
```xml
...
```
In code:
```kt
topAppBar.setNavigationOnClickListener {
drawerLayout.open()
}
navigationView.setNavigationItemSelectedListener { menuItem ->
// Handle menu item selected
menuItem.isChecked = true
drawerLayout.close()
true
}
```
For more information on top app bars see the
[documentation](https://github.com/material-components/material-components-android/tree/master/docs/components/TopAppBar.md).
## Predictive Back
The `NavigationView` component automatically supports
[Predictive Back](../foundations/PredictiveBack.md) when it is set up within a
`DrawerLayout`, as mentioned in the sections above. No further integration is
required on the app side other than the general Predictive Back prerequisites
and migration steps mentioned [here](../foundations/PredictiveBack.md#usage).
Visit the
[Predictive Back design guidelines](https://m3.material.io/components/side-sheets/guidelines#d77245e3-1013-48f8-a9d7-76f484e1be13)
to see how the component behaves when a user swipes back.
## Theming
Navigation drawers support
[Material Theming](https://material.io/components/text-fields/#theming) which
can customize color, typography and shape.
### Navigation drawer theming example
API and source code:
* `NavigationView`
* [Class definition](https://developer.android.com/reference/com/google/android/material/navigation/NavigationView)
* [GitHub source](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/NavigationView.java)
The following example shows a navigation drawer with Material Theming.

#### Implementing navigation drawer theming
Use theme attributes, default style theme attributes, and styles in
`res/values/styles.xml`, which applies to all navigation drawers and affects
other components:
```xml
```
In `res/color/navigation_item_color.xml`:
```xml
```
In `res/color/navigation_item_background_color.xml`:
```xml
```
Use default style theme attributes, styles and theme overlays which apply to all
navigation drawers but do not affect other components:
```xml
```
Use the style in the layout, which affects only this navigation drawer:
```xml
```