Skip to content

Commit 44a97f4

Browse files
pubiqqleticiarossi
authored andcommitted
[Badge] Fix table formatting and remove unnecessary badge invalidation
Resolves #3356 GIT_ORIGIN_REV_ID=9f6839aa225d567a26a7db948734c28a1bbae44a PiperOrigin-RevId: 526735605
1 parent b335436 commit 44a97f4

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

docs/components/BadgeDrawable.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,20 @@ center, use `setHorizontalOffset(int)` or `setVerticalOffset(int)`
9292

9393
| Feature | Relevant attributes |
9494
|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
95-
| Color | `app:backgroundColor` <br> `app:badgeTextColor` |
95+
| Color | `app:backgroundColor` <br> `app:badgeTextColor` |
9696
| Width | `app:badgeWidth` <br> `app:badgeWithTextWidth` |
9797
| Height | `app:badgeHeight` <br> `app:badgeWithTextHeight` |
98-
| Shape | `app:badgeShapeAppearance` <br> `app:badgeShapeAppearanceOverlay` <br> `app:badgeWithTextShapeAppearance` <br> `app:badgeWithTextShapeAppearanceOverlay` |
99-
| Label | `app:badgeText` (for text) <br> `app:number` (for numbers) |
100-
| Label Length | `app:maxCharacterCount` (for all text) <br> `app:maxNumber` (for numbers only) |
98+
| Shape | `app:badgeShapeAppearance` <br> `app:badgeShapeAppearanceOverlay` <br> `app:badgeWithTextShapeAppearance` <br> `app:badgeWithTextShapeAppearanceOverlay` |
99+
| Label | `app:badgeText` (for text) <br> `app:number` (for numbers) |
100+
| Label Length | `app:maxCharacterCount` (for all text) <br> `app:maxNumber` (for numbers only) |
101101
| Label Text Color | `app:badgeTextColor` |
102102
| Label Text Appearance | `app:badgeTextAppearance` |
103103
| Badge Gravity | `app:badgeGravity` |
104104
| Offset Alignment | `app:offsetAlignmentMode` |
105105
| Horizontal Padding | `app:badgeWidePadding` |
106106
| Vertical Padding | `app:badgeVerticalPadding` |
107107
| Auto Adjust | `app:autoAdjustToWithinGrandparentBounds` |
108+
108109
**Note:** If both `app:badgeText` and `app:number` are specified, the badge label will be `app:badgeText`.
109110

110111
### Talkback Support

lib/java/com/google/android/material/badge/BadgeDrawable.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public void updateBadgeCoordinates(
373373
private boolean isAnchorViewWrappedInCompatParent() {
374374
View customBadgeAnchorParent = getCustomBadgeParent();
375375
return customBadgeAnchorParent != null
376-
&& customBadgeAnchorParent.getId() == R.id.mtrl_anchor_parent;
376+
&& customBadgeAnchorParent.getId() == R.id.mtrl_anchor_parent;
377377
}
378378

379379
/** Returns a {@link FrameLayout} that will set this {@code BadgeDrawable} as its foreground. */
@@ -539,8 +539,10 @@ public void setNumber(int number) {
539539

540540
/** Clears the badge's number. */
541541
public void clearNumber() {
542-
state.clearNumber();
543-
onNumberUpdated();
542+
if (state.hasNumber()) {
543+
state.clearNumber();
544+
onNumberUpdated();
545+
}
544546
}
545547

546548
private void onNumberUpdated() {

lib/java/com/google/android/material/badge/res/values/integers.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
-->
1717

1818
<resources>
19+
<!-- Not used. Kept for backward compatibility -->
1920
<integer name="mtrl_badge_max_character_count">4</integer>
2021
<integer name="m3_badge_max_number">999</integer>
2122
</resources>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<item name="badgeWithTextHeight">@dimen/mtrl_badge_with_text_size</item>
2424
<item name="badgeWidePadding">@dimen/mtrl_badge_long_text_horizontal_padding</item>
2525
<item name="backgroundColor">?attr/colorError</item>
26-
<item name="maxNumber">999</item>
26+
<item name="maxNumber">@integer/m3_badge_max_number</item>
2727
<item name="badgeGravity">TOP_END</item>
2828
<item name="offsetAlignmentMode">legacy</item>
2929
<item name="badgeTextAppearance">@style/TextAppearance.MaterialComponents.Badge</item>

0 commit comments

Comments
 (0)