Skip to content

Commit 7428b2b

Browse files
leticiarossikendrickumstattd
authored andcommitted
[OverflowLinearLayout][Button] Overflow menu item's text should be CharSequence
PiperOrigin-RevId: 764904265
1 parent e7f9f63 commit 7428b2b

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lib/java/com/google/android/material/button/MaterialButtonGroup.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private MenuItem addMenuItemForButton(@NonNull Menu menu, @NonNull Button button
483483
}
484484
MaterialButtonGroup.LayoutParams lp =
485485
(MaterialButtonGroup.LayoutParams) button.getLayoutParams();
486-
String text = OverflowUtils.getMenuItemText(button, lp.overflowText);
486+
CharSequence text = OverflowUtils.getMenuItemText(button, lp.overflowText);
487487
Drawable icon = lp.overflowIcon;
488488
MenuItem item = menu.add(text);
489489
if (icon != null) {
@@ -1121,7 +1121,7 @@ protected boolean checkLayoutParams(@NonNull ViewGroup.LayoutParams p) {
11211121
/** A {@link LinearLayout.LayoutParams} implementation for {@link MaterialButtonGroup}. */
11221122
public static class LayoutParams extends LinearLayout.LayoutParams {
11231123
@Nullable public Drawable overflowIcon = null;
1124-
@Nullable public String overflowText = null;
1124+
@Nullable public CharSequence overflowText = null;
11251125

11261126
/**
11271127
* Creates a new set of layout parameters. The values are extracted from the supplied attributes
@@ -1138,7 +1138,7 @@ public LayoutParams(@NonNull Context context, @Nullable AttributeSet attrs) {
11381138
overflowIcon =
11391139
attributes.getDrawable(R.styleable.MaterialButtonGroup_Layout_layout_overflowIcon);
11401140
overflowText =
1141-
attributes.getString(R.styleable.MaterialButtonGroup_Layout_layout_overflowText);
1141+
attributes.getText(R.styleable.MaterialButtonGroup_Layout_layout_overflowText);
11421142

11431143
attributes.recycle();
11441144
}
@@ -1161,14 +1161,14 @@ public LayoutParams(int width, int height, float weight) {
11611161
* in pixels
11621162
* @param weight the weight
11631163
* @param overflowIcon the overflow icon drawable
1164-
* @param overflowText the overflow text string
1164+
* @param overflowText the overflow text char sequence
11651165
*/
11661166
public LayoutParams(
11671167
int width,
11681168
int height,
11691169
float weight,
11701170
@Nullable Drawable overflowIcon,
1171-
@Nullable String overflowText) {
1171+
@Nullable CharSequence overflowText) {
11721172
super(width, height, weight);
11731173
this.overflowIcon = overflowIcon;
11741174
this.overflowText = overflowText;
@@ -1209,17 +1209,17 @@ public static class OverflowUtils {
12091209
private OverflowUtils() {}
12101210

12111211
@Nullable
1212-
public static String getMenuItemText(@NonNull View view, @Nullable String text) {
1212+
public static CharSequence getMenuItemText(@NonNull View view, @Nullable CharSequence text) {
12131213
if (!TextUtils.isEmpty(text)) {
12141214
return text;
12151215
}
12161216
if (view instanceof MaterialButton && !TextUtils.isEmpty(((MaterialButton) view).getText())) {
12171217
// Use button's text if overflow text is not specified or empty. We don't do this to icon,
12181218
// since icon in menu item is optional.
1219-
return (String) ((MaterialButton) view).getText();
1219+
return ((MaterialButton) view).getText();
12201220
}
12211221
// As a last resort, use content description.
1222-
return (String) view.getContentDescription();
1222+
return view.getContentDescription();
12231223
}
12241224
}
12251225
}

lib/java/com/google/android/material/overflow/OverflowLinearLayout.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private void handleOverflowButtonClick(PopupMenu popupMenu, int overflowItemIcon
264264
OverflowLinearLayout.LayoutParams lp =
265265
(OverflowLinearLayout.LayoutParams) view.getLayoutParams();
266266

267-
String text = OverflowUtils.getMenuItemText(view, lp.overflowText);
267+
CharSequence text = OverflowUtils.getMenuItemText(view, lp.overflowText);
268268
MenuItem item = popupMenu.getMenu().add(text);
269269
Drawable icon = lp.overflowIcon;
270270
if (icon != null) {
@@ -330,7 +330,7 @@ protected boolean checkLayoutParams(@NonNull ViewGroup.LayoutParams p) {
330330
/** A {@link LinearLayout.LayoutParams} implementation for {@link OverflowLinearLayout}. */
331331
public static class LayoutParams extends LinearLayout.LayoutParams {
332332
@Nullable public Drawable overflowIcon = null;
333-
@Nullable public String overflowText = null;
333+
@Nullable public CharSequence overflowText = null;
334334

335335
/**
336336
* Creates a new set of layout parameters. The values are extracted from the supplied attributes
@@ -347,7 +347,7 @@ public LayoutParams(@NonNull Context context, @Nullable AttributeSet attrs) {
347347
overflowIcon =
348348
attributes.getDrawable(R.styleable.OverflowLinearLayout_Layout_layout_overflowIcon);
349349
overflowText =
350-
attributes.getString(R.styleable.OverflowLinearLayout_Layout_layout_overflowText);
350+
attributes.getText(R.styleable.OverflowLinearLayout_Layout_layout_overflowText);
351351

352352
attributes.recycle();
353353
}
@@ -370,14 +370,14 @@ public LayoutParams(int width, int height, float weight) {
370370
* in pixels
371371
* @param weight the weight
372372
* @param overflowIcon the overflow icon drawable
373-
* @param overflowText the overflow text string
373+
* @param overflowText the overflow text char sequence
374374
*/
375375
public LayoutParams(
376376
int width,
377377
int height,
378378
float weight,
379379
@Nullable Drawable overflowIcon,
380-
@Nullable String overflowText) {
380+
@Nullable CharSequence overflowText) {
381381
super(width, height, weight);
382382
this.overflowIcon = overflowIcon;
383383
this.overflowText = overflowText;

0 commit comments

Comments
 (0)