Skip to content

Commit 022e217

Browse files
committed
[Navigation] Add itemTextAppearanceActiveBoldEnabled attr
Resolves #3191 Resolves #3293 PiperOrigin-RevId: 539977391
1 parent 4d80434 commit 022e217

File tree

23 files changed

+214
-37
lines changed

23 files changed

+214
-37
lines changed

catalog/java/io/material/catalog/bottomnav/BottomNavigationDemoFragment.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.android.material.badge.BadgeDrawable;
3535
import com.google.android.material.badge.BadgeDrawable.BadgeGravity;
3636
import com.google.android.material.bottomnavigation.BottomNavigationView;
37+
import com.google.android.material.materialswitch.MaterialSwitch;
3738
import com.google.android.material.navigation.NavigationBarView.OnItemSelectedListener;
3839
import io.material.catalog.feature.DemoFragment;
3940
import io.material.catalog.feature.DemoUtils;
@@ -193,6 +194,15 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
193194
@Override
194195
public void onNothingSelected(AdapterView<?> parent) {}
195196
});
197+
198+
MaterialSwitch materialSwitch = view.findViewById(R.id.bold_text_switch);
199+
materialSwitch.setChecked(true);
200+
materialSwitch.setOnCheckedChangeListener(
201+
(buttonView, isChecked) -> {
202+
for (BottomNavigationView bn : bottomNavigationViews) {
203+
bn.setItemTextAppearanceActiveBoldEnabled(isChecked);
204+
}
205+
});
196206
}
197207

198208
private void initAddIncreaseBadgeNumberButton(Button incrementBadgeNumberButton) {

catalog/java/io/material/catalog/bottomnav/res/layout/cat_bottom_nav_fragment.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,22 @@
102102
android:layout_width="wrap_content"
103103
android:layout_height="48dp"/>
104104
</LinearLayout>
105-
105+
<LinearLayout
106+
android:layout_width="wrap_content"
107+
android:layout_height="wrap_content"
108+
android:orientation="horizontal">
109+
<TextView
110+
android:layout_width="wrap_content"
111+
android:layout_height="wrap_content"
112+
android:layout_gravity="end|center_vertical"
113+
android:labelFor="@+id/bold_text_switch"
114+
android:text="@string/cat_bottom_nav_label_active_bold" />
115+
<com.google.android.material.materialswitch.MaterialSwitch
116+
android:id="@+id/bold_text_switch"
117+
android:layout_width="wrap_content"
118+
android:layout_height="wrap_content"
119+
android:layout_marginStart="12dp" />
120+
</LinearLayout>
106121
</LinearLayout>
107122
</ScrollView>
108123
<FrameLayout

catalog/java/io/material/catalog/bottomnav/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<string name="cat_bottom_nav_badge_gravity_bottom_start">Bottom start</string>
5858

5959
<string name="cat_bottom_nav_badge_gravity_spinner_label">Badge gravity</string>
60+
<string name="cat_bottom_nav_label_active_bold" translatable="false">Bold active label</string>
6061

6162
</resources>
6263

catalog/java/io/material/catalog/navigationdrawer/NavigationDrawerDemoActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import androidx.annotation.Nullable;
3030
import androidx.drawerlayout.widget.DrawerLayout;
3131
import androidx.drawerlayout.widget.DrawerLayout.SimpleDrawerListener;
32+
import com.google.android.material.materialswitch.MaterialSwitch;
3233
import com.google.android.material.navigation.NavigationView;
3334
import io.material.catalog.feature.DemoActivity;
3435

@@ -89,6 +90,14 @@ public void onDrawerClosed(@NonNull View drawerView) {
8990
view.findViewById(R.id.show_end_drawer_gravity)
9091
.setOnClickListener(v -> drawerLayout.openDrawer(navigationViewEnd));
9192

93+
MaterialSwitch materialSwitch = view.findViewById(R.id.bold_text_switch);
94+
materialSwitch.setChecked(true);
95+
materialSwitch.setOnCheckedChangeListener(
96+
(buttonView, isChecked) -> {
97+
navigationViewStart.setItemTextAppearanceActiveBoldEnabled(isChecked);
98+
navigationViewEnd.setItemTextAppearanceActiveBoldEnabled(isChecked);
99+
});
100+
92101
return view;
93102
}
94103

catalog/java/io/material/catalog/navigationdrawer/res/layout/cat_navigationdrawer.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@
6666
android:layout_marginTop="32dp"
6767
android:text="@string/cat_navigationdrawer_show_end_drawer" />
6868

69+
<LinearLayout
70+
android:layout_width="wrap_content"
71+
android:layout_height="wrap_content"
72+
android:orientation="horizontal">
73+
<TextView
74+
android:layout_width="wrap_content"
75+
android:layout_height="wrap_content"
76+
android:layout_gravity="end|center_vertical"
77+
android:labelFor="@+id/bold_text_switch"
78+
android:text="@string/cat_navigationdrawer_label_active_bold" />
79+
<com.google.android.material.materialswitch.MaterialSwitch
80+
android:id="@+id/bold_text_switch"
81+
android:layout_width="wrap_content"
82+
android:layout_height="wrap_content"
83+
android:layout_marginStart="12dp" />
84+
</LinearLayout>
85+
6986
</LinearLayout>
7087
</androidx.coordinatorlayout.widget.CoordinatorLayout>
7188

@@ -75,6 +92,7 @@
7592
android:layout_height="match_parent"
7693
android:layout_gravity="start"
7794
app:headerLayout="@layout/cat_navigationdrawer_header"
95+
app:itemTextAppearanceActiveBoldEnabled="true"
7896
app:menu="@menu/cat_navigationdrawer_menu"/>
7997

8098
<com.google.android.material.navigation.NavigationView
@@ -83,6 +101,7 @@
83101
android:layout_height="match_parent"
84102
android:layout_gravity="end"
85103
app:headerLayout="@layout/cat_navigationdrawer_header"
104+
app:itemTextAppearanceActiveBoldEnabled="true"
86105
app:menu="@menu/cat_navigationdrawer_menu"/>
87106

88107
</androidx.drawerlayout.widget.DrawerLayout>

catalog/java/io/material/catalog/navigationdrawer/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
description="Label for opening the navigation drawer at the end of the screen. [CHAR_LIMIT=100]">
3535
Open End Drawer
3636
</string>
37+
<string name="cat_navigationdrawer_label_active_bold" translatable="false">Bold active label</string>
3738
<string name="cat_navigationdrawer_header_mail">Mail</string>
3839
<string name="cat_navigationdrawer_header_labels">Labels</string>
3940
<string name="cat_navigationdrawer_label">Label</string>

catalog/java/io/material/catalog/navigationrail/NavigationRailDemoFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import androidx.core.math.MathUtils;
3636
import com.google.android.material.badge.BadgeDrawable;
3737
import com.google.android.material.badge.BadgeDrawable.BadgeGravity;
38+
import com.google.android.material.materialswitch.MaterialSwitch;
3839
import com.google.android.material.navigation.NavigationBarView.OnItemSelectedListener;
3940
import com.google.android.material.navigationrail.NavigationRailView;
4041
import io.material.catalog.feature.DemoFragment;
@@ -187,6 +188,12 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
187188
@Override
188189
public void onNothingSelected(AdapterView<?> parent) {}
189190
});
191+
192+
MaterialSwitch materialSwitch = view.findViewById(R.id.bold_text_switch);
193+
materialSwitch.setChecked(true);
194+
materialSwitch.setOnCheckedChangeListener(
195+
(buttonView, isChecked) ->
196+
navigationRailView.setItemTextAppearanceActiveBoldEnabled(isChecked));
190197
}
191198

192199
private void initAddIncreaseBadgeNumberButton(Button incrementBadgeNumberButton) {

catalog/java/io/material/catalog/navigationrail/res/layout/cat_navigation_rail_fragment.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,22 @@
124124
android:layout_width="wrap_content"
125125
android:layout_height="48dp"/>
126126
</LinearLayout>
127-
127+
<LinearLayout
128+
android:layout_width="wrap_content"
129+
android:layout_height="wrap_content"
130+
android:orientation="horizontal">
131+
<TextView
132+
android:layout_width="wrap_content"
133+
android:layout_height="wrap_content"
134+
android:layout_gravity="end|center_vertical"
135+
android:labelFor="@+id/bold_text_switch"
136+
android:text="@string/cat_navigation_rail_label_active_bold" />
137+
<com.google.android.material.materialswitch.MaterialSwitch
138+
android:id="@+id/bold_text_switch"
139+
android:layout_width="wrap_content"
140+
android:layout_height="wrap_content"
141+
android:layout_marginStart="12dp" />
142+
</LinearLayout>
128143
</LinearLayout>
129144
</ScrollView>
130145
</LinearLayout>

catalog/java/io/material/catalog/navigationrail/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
description="Label for the option that will cause badges to be positioned at the end, below the icon. [CHAR_LIMIT=50]">Bottom end</string>
9494
<string name="cat_navigation_rail_badge_gravity_bottom_start"
9595
description="Label for the option that will cause badges to be positioned at starting, below the icon. [CHAR_LIMIT=50]">Bottom start</string>
96+
<string name="cat_navigation_rail_label_active_bold"
97+
description="Label for controlling whether the active label is bold. [CHAR_LIMIT=50]" translatable="false">Bold active label</string>
9698

9799
<string name="cat_navigation_rail_alarm"
98100
description="Label for an alarm icon. [CHAR_LIMIT=50]">Alarm</string>

docs/components/BottomNavigation.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,14 @@ The following is an anatomy diagram for the bottom navigation bar:
282282

283283
#### Text label attributes
284284

285-
**Element** | **Attribute** | **Related methods** | **Default value**
286-
------------------------- | -------------------------------------- | ------------------------------------------------------------------- | -----------------
287-
**Text label** | `android:title` in the `menu` resource | N/A | N/A
288-
**Color (inactive)** | `app:itemTextColor` | `setItemTextColor`<br/>`getItemTextColor` | `?attr/colorOnSurfaceVariant` (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/res/color/m3_navigation_bar_item_with_indicator_label_tint.xml))
289-
**Color (active)** | " | " | `?attr/colorOnSurface` (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/res/color/m3_navigation_bar_item_with_indicator_label_tint.xml))
290-
**Typography (inactive)** | `app:itemTextAppearanceInactive` | `setItemTextAppearanceInactive`<br/>`getItemTextAppearanceInactive` | `?attr/textAppearanceTitleSmall`
291-
**Typography (active)** | `app:itemTextAppearanceActive` | `setItemTextAppearanceActive`<br/>`getItemTextAppearanceActive` | `?attr/textAppearanceTitleSmall`
285+
| **Element** | **Attribute** | **Related methods** | **Default value** |
286+
|---------------------------|-------------------------------------------|---------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
287+
| **Text label** | `android:title` in the `menu` resource | N/A | N/A |
288+
| **Color (inactive)** | `app:itemTextColor` | `setItemTextColor`<br/>`getItemTextColor` | `?attr/colorOnSurfaceVariant` (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/res/color/m3_navigation_bar_item_with_indicator_label_tint.xml)) |
289+
| **Color (active)** | " | " | `?attr/colorOnSurface` (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/res/color/m3_navigation_bar_item_with_indicator_label_tint.xml)) |
290+
| **Typography (inactive)** | `app:itemTextAppearanceInactive` | `setItemTextAppearanceInactive`<br/>`getItemTextAppearanceInactive` | `?attr/textAppearanceTitleSmall` |
291+
| **Typography (active)** | `app:itemTextAppearanceActive` | `setItemTextAppearanceActive`<br/>`getItemTextAppearanceActive` | `?attr/textAppearanceTitleSmall` |
292+
| **Typography (active)** | `app:itemTextAppearanceActiveBoldEnabled` | `setItemTextAppearanceActiveBoldEnabled` | `true` |
292293

293294
#### Styles
294295

0 commit comments

Comments
 (0)