Skip to content

Commit 7bd9724

Browse files
imhappidrchen
authored andcommitted
[BottomNavigationView] Integrate tokens and add shape appearance support
PiperOrigin-RevId: 524919091
1 parent add7f5d commit 7bd9724

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
<attr name="android:minHeight" />
2727
<!-- Whether or not to add a shadow with a divider that is compatible across pre-21 legacy backgrounds. -->
2828
<attr name="compatShadowEnabled" format="boolean"/>
29+
<!-- Shape appearance style reference for BottomNavigationView. Attribute declaration is in the Shape package. -->
30+
<attr name="shapeAppearance"/>
31+
<!-- Shape appearance overlay style reference for BottomNavigationView. To be used to augment
32+
attributes declared in the shapeAppearance. Attribute declaration is in the Shape package. -->
33+
<attr name="shapeAppearanceOverlay"/>
2934
</declare-styleable>
3035

3136
</resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<item name="itemPaddingBottom">@dimen/m3_bottom_nav_item_padding_bottom</item>
8080
<item name="android:minHeight">@dimen/m3_bottom_nav_min_height</item>
8181
<item name="materialThemeOverlay">@style/ThemeOverlay.Material3.BottomNavigationView</item>
82+
<item name="shapeAppearance">@style/ShapeAppearance.M3.Comp.NavigationBar.Container.Shape</item>
8283
</style>
8384

8485
<style name="Widget.Material3.BottomNavigationView" parent="Base.Widget.Material3.BottomNavigationView">

lib/java/com/google/android/material/bottomnavigation/res/values/tokens.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<!-- Generated from token set (md.comp.navigation-bar) in context (platform=android, audience=3p). -->
2323
<!-- Enabled - Container -->
2424
<macro name="m3_comp_navigation_bar_container_color">?attr/colorSurface</macro>
25+
<style name="ShapeAppearance.M3.Comp.NavigationBar.Container.Shape" parent="ShapeAppearance.M3.Sys.Shape.Corner.None"/>
2526
<dimen name="m3_comp_navigation_bar_container_height">80dp</dimen>
2627
<dimen name="m3_comp_navigation_bar_container_elevation">@dimen/m3_sys_elevation_level2</dimen>
2728
<!-- Enabled - Label text -->

lib/java/com/google/android/material/navigation/NavigationBarView.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ public NavigationBarView(
193193

194194
if (getBackground() == null || getBackground() instanceof ColorDrawable) {
195195
// Add a MaterialShapeDrawable as background that supports tinting in every API level.
196-
ViewCompat.setBackground(this, createMaterialShapeDrawableBackground(context));
196+
ViewCompat.setBackground(this, createMaterialShapeDrawableBackground(context,
197+
ShapeAppearanceModel.builder(context, attrs, defStyleAttr, defStyleRes).build()));
197198
}
198199

199200
if (attributes.hasValue(R.styleable.NavigationBarView_itemPaddingTop)) {
@@ -297,14 +298,16 @@ public void onMenuModeChange(MenuBuilder menu) {}
297298
}
298299

299300
@NonNull
300-
private MaterialShapeDrawable createMaterialShapeDrawableBackground(Context context) {
301+
private MaterialShapeDrawable createMaterialShapeDrawableBackground(
302+
Context context, ShapeAppearanceModel shapeAppearanceModel) {
301303
MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable();
302304
Drawable originalBackground = getBackground();
303305
if (originalBackground instanceof ColorDrawable) {
304306
materialShapeDrawable.setFillColor(
305307
ColorStateList.valueOf(((ColorDrawable) originalBackground).getColor()));
306308
}
307309
materialShapeDrawable.initializeElevationOverlay(context);
310+
materialShapeDrawable.setShapeAppearanceModel(shapeAppearanceModel);
308311
return materialShapeDrawable;
309312
}
310313

0 commit comments

Comments
 (0)