Skip to content

Commit 015e053

Browse files
dsn5ftimhappi
authored andcommitted
[Toolbar] Add support for navigation button with circle background
PiperOrigin-RevId: 790777821
1 parent 7fe9ef9 commit 015e053

File tree

8 files changed

+73
-0
lines changed

8 files changed

+73
-0
lines changed

catalog/java/io/material/catalog/topappbar/res/layout/cat_topappbar_toolbar_fragment.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,13 @@
5050
android:elevation="@dimen/design_appbar_elevation"
5151
app:subtitle="Surface Elevated"
5252
app:title="Toolbar"/>
53+
54+
<com.google.android.material.appbar.MaterialToolbar
55+
android:layout_width="match_parent"
56+
android:layout_height="wrap_content"
57+
android:layout_marginTop="32dp"
58+
android:theme="@style/ThemeOverlay.Material3.Toolbar.CircleNavigationButton"
59+
app:subtitle="Circle Navigation Button"
60+
app:title="Toolbar" />
5361
</LinearLayout>
5462
</ScrollView>

docs/components/TopAppBar.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,22 @@ layout configuration.
596596

597597
<details>
598598

599+
<summary><h3>Adding a circle to the navigation button</h3></summary>
600+
601+
If you would like to add a circle background to the navigation icon, set the
602+
`android:theme="@style/ThemeOverlay.Material3.Toolbar.CircleNavigationButton"`
603+
theme overlay on your `Toolbar` or `MaterialToolbar`.
604+
605+
By default, the theme overlay above uses `?attr/colorSurfaceContainer` for the
606+
circle color. This can be customized by extending the theme overlay and setting
607+
the `toolbarNavigationButtonCircleColor` attribute.
608+
609+
<img src="assets/topappbar/topappbar_circle_nav_button.png" alt="Top app bar with circle navigation button background." width="600"/>
610+
611+
</details>
612+
613+
<details>
614+
599615
<summary><h3>Applying scrolling behavior to app bars</h3></summary>
600616

601617
When scrolling up, the collapsing top app bar transforms into a regular top app
36.7 KB
Loading

lib/java/com/google/android/material/appbar/res-public/values/public.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<public name="collapsingToolbarLayoutMediumSize" type="attr"/>
2323
<public name="collapsingToolbarLayoutLargeSize" type="attr"/>
2424
<public name="toolbarSurfaceStyle" type="attr"/>
25+
<public name="toolbarNavigationButtonCircleColor" type="attr"/>
2526
<public name="layout_scrollInterpolator" type="attr"/>
2627
<public name="layout_scrollEffect" type="attr"/>
2728
<public name="behavior_overlapTop" type="attr"/>
@@ -64,12 +65,14 @@
6465
<public name="Widget.Material3.Toolbar" type="style"/>
6566
<public name="Widget.Material3.Toolbar.Surface" type="style"/>
6667
<public name="Widget.Material3.Toolbar.OnSurface" type="style"/>
68+
<public name="Widget.Material3.Toolbar.Button.Navigation.Circle" type="style"/>
6769
<public name="Widget.Material3.ActionBar.Solid" type="style"/>
6870
<public name="Widget.Material3.Light.ActionBar.Solid" type="style"/>
6971
<public name="Widget.Material3.ActionMode" type="style"/>
7072
<public name="ThemeOverlay.MaterialComponents.Toolbar.Primary" type="style"/>
7173
<public name="ThemeOverlay.MaterialComponents.Toolbar.Surface" type="style"/>
7274
<public name="ThemeOverlay.Material3.Toolbar.Surface" type="style"/>
75+
<public name="ThemeOverlay.Material3.Toolbar.CircleNavigationButton" type="style"/>
7376
<public name="TextAppearance.Design.CollapsingToolbar.Expanded" type="style"/>
7477
<public name="TextAppearance.Material3.ActionBar.Subtitle" type="style"/>
7578
<public name="TextAppearance.Material3.ActionBar.Title" type="style"/>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2025 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
18+
19+
<!-- Circle. -->
20+
<item
21+
android:width="@dimen/m3_toolbar_button_circle_size"
22+
android:height="@dimen/m3_toolbar_button_circle_size"
23+
android:gravity="center">
24+
<shape android:shape="oval">
25+
<solid android:color="?attr/toolbarNavigationButtonCircleColor" />
26+
</shape>
27+
</item>
28+
29+
<!-- Ripple, which should be on top of the Circle but below the Icon. -->
30+
<item
31+
android:drawable="?attr/controlBackground"
32+
android:gravity="center" />
33+
</layer-list>

lib/java/com/google/android/material/appbar/res/values/attrs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<!-- Style to use for Surface Toolbars in this theme. -->
3838
<attr name="toolbarSurfaceStyle" format="reference"/>
3939

40+
<!-- Color of the circle when using ThemeOverlay.Material3.Toolbar.CircleNavigationButton. -->
41+
<attr name="toolbarNavigationButtonCircleColor" format="color"/>
42+
4043
<declare-styleable name="AppBarLayout">
4144
<!-- Deprecated. Elevation is now controlled via a state list animator. -->
4245
<attr name="elevation"/>

lib/java/com/google/android/material/appbar/res/values/dimens.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@
3333
<dimen name="m3_appbar_scrim_height_trigger_medium">112dp</dimen>
3434
<dimen name="m3_appbar_scrim_height_trigger_large">112dp</dimen>
3535
<dimen name="m3_toolbar_text_size_title">20dp</dimen>
36+
<dimen name="m3_toolbar_button_circle_size">40dp</dimen>
3637
</resources>

lib/java/com/google/android/material/appbar/res/values/styles.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@
154154
<item name="colorControlNormal">@macro/m3_comp_app_bar_trailing_icon_color</item>
155155
</style>
156156

157+
<style name="ThemeOverlay.Material3.Toolbar.CircleNavigationButton" parent="">
158+
<item name="toolbarNavigationButtonCircleColor">?attr/colorSurfaceContainer</item>
159+
<item name="toolbarNavigationButtonStyle">@style/Widget.Material3.Toolbar.Button.Navigation.Circle</item>
160+
</style>
161+
162+
<style name="Widget.Material3.Toolbar.Button.Navigation.Circle" parent="Widget.AppCompat.Toolbar.Button.Navigation">
163+
<item name="android:background">@drawable/m3_toolbar_navigation_circle_background</item>
164+
</style>
165+
157166
<!-- Style for a M3 ActionBar (inherited from AppCompat due to different
158167
desired configuration compared to MaterialComponents ActionBars). -->
159168
<style name="Base.Widget.Material3.ActionBar.Solid" parent="Widget.AppCompat.ActionBar.Solid">

0 commit comments

Comments
 (0)