Skip to content

Commit 5f44dbc

Browse files
imhappipaulfthomas
authored andcommitted
[NavigationRail][Docs] Update navigation rail docs to include mentions of the expanded nav rail
PiperOrigin-RevId: 699270265
1 parent c24c67d commit 5f44dbc

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

docs/components/NavigationRail.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ A typical layout will look similar to this:
4444
```
4545

4646
**Note:** The width of a `NavigationRailView` will be 80dp wide by default.The
47-
width of the rail can be changed by setting the `android:layout_width`attribute
47+
width of the rail can be changed by setting the `android:layout_width` attribute
4848
to a specific DP value.
4949

5050
In `navigation_rail_menu.xml` inside a `menu` resource directory:
@@ -74,11 +74,48 @@ In `navigation_rail_menu.xml` inside a `menu` resource directory:
7474
</menu>
7575
```
7676

77-
**Note:** `NavigationRailView` displays three to no more than seven app
78-
destinations, and can include a header view. Each destination is represented by
79-
an icon and a text label.
77+
`NavigationRailView` displays three to no more than seven app
78+
destinations when collapsed, and can include a header view. Each destination is
79+
represented by an icon and a text label.
8080

81-
In code:
81+
You can also define submenus for the Navigation Rail like below:
82+
83+
```xml
84+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
85+
<item
86+
android:id="@+id/submenu_1"
87+
android:title="@string/subheader_1_name">
88+
<menu>
89+
<item
90+
android:id="@+id/timer"
91+
android:enabled="true"
92+
android:icon="@drawable/icon_sand_clock"
93+
android:title="@string/timer_destination_label"/>
94+
<item
95+
android:id="@+id/stopwatch"
96+
android:enabled="true"
97+
android:icon="@drawable/icon_stop_watch"
98+
android:title="@string/stopwatch_destination_label"/>
99+
</menu>
100+
</item>
101+
<item
102+
android:id="@+id/alarms"
103+
android:enabled="true"
104+
android:icon="@drawable/icon_alarms"
105+
android:title="@string/alarms_destination_label"/>
106+
<item
107+
android:id="@+id/schedule"
108+
android:enabled="true"
109+
android:icon="@drawable/icon_clock"
110+
android:title="@string/schedule_destination_label"/>
111+
</menu>
112+
```
113+
114+
Navigation rails are collapsed by default. When collapsed, only menu items that
115+
are not under a submenu will be shown, up to a limit of 7. There is no limit of
116+
items shown when expanded.
117+
118+
You will need to set listeners for the menu items in code:
82119

83120
```kt
84121
// Listeners are defined on the super class NavigationBarView
@@ -188,6 +225,22 @@ The following methods can be used to manipulate the header view at runtime.
188225
-------------------------------- | ---------------
189226
`@Nullable view getHeaderView()` | Returns an instance of the header view associated with the Navigation Rail, null if none was currently attached.
190227

228+
### Expanding the Navigation Rail
229+
230+
You can call `navigationRailView.expand()` and `navigationRailView.collapse()` to expand and collapse the navigation rail.
231+
232+
When collapsed, only menu items not under a submenu will be shown, up to a limit of 7.
233+
234+
When expanded, all menu items will be shown, including submenu items.
235+
236+
Navigation rails are collapsed by default which animates into the expanded navigation rail when expanded. If the content beside
237+
the navigation rail takes into account the size of the navigation rail (ie., through setting constraints in `ConstraintLayout` or layout weights) then the content will also be animated to shrink. This animation is taken care of by a [ChangeBounds Transition](https://developer.android.com/reference/android/transition/ChangeBounds); any animations during the expansion of the navigation rail should be 'turned off' as
238+
it could result in a strange animation due to the `Transition`.
239+
240+
Collapsed Navigation Rail | Expanded Navigation Rail
241+
-------------------------------------------------------------------------- | ------------------------
242+
![Collapsed navigation rail](assets/navigationrail/collapsed_nav_rail.png) | ![Expanded navigation rail](assets/navigationrail/expanded_nav_rail.png)
243+
191244
### Adding badges
192245

193246
Rail icons can include badges on the upper right corner of the icon. Badges
Loading
Loading

0 commit comments

Comments
 (0)