Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/components/BadgeDrawable.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,20 @@ center, use `setHorizontalOffset(int)` or `setVerticalOffset(int)`

| Feature | Relevant attributes |
|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| Color | `app:backgroundColor` <br> `app:badgeTextColor` |
| Color | `app:backgroundColor` <br> `app:badgeTextColor` |
| Width | `app:badgeWidth` <br> `app:badgeWithTextWidth` |
| Height | `app:badgeHeight` <br> `app:badgeWithTextHeight` |
| Shape | `app:badgeShapeAppearance` <br> `app:badgeShapeAppearanceOverlay` <br> `app:badgeWithTextShapeAppearance` <br> `app:badgeWithTextShapeAppearanceOverlay` |
| Label | `app:badgeText` (for text) <br> `app:number` (for numbers) |
| Label Length | `app:maxCharacterCount` (for all text) <br> `app:maxNumber` (for numbers only) |
| Shape | `app:badgeShapeAppearance` <br> `app:badgeShapeAppearanceOverlay` <br> `app:badgeWithTextShapeAppearance` <br> `app:badgeWithTextShapeAppearanceOverlay` |
| Label | `app:badgeText` (for text) <br> `app:number` (for numbers) |
| Label Length | `app:maxCharacterCount` (for all text) <br> `app:maxNumber` (for numbers only) |
| Label Text Color | `app:badgeTextColor` |
| Label Text Appearance | `app:badgeTextAppearance` |
| Badge Gravity | `app:badgeGravity` |
| Offset Alignment | `app:offsetAlignmentMode` |
| Horizontal Padding | `app:badgeWidePadding` |
| Vertical Padding | `app:badgeVerticalPadding` |
| Auto Adjust | `app:autoAdjustToWithinGrandparentBounds` |

**Note:** If both `app:badgeText` and `app:number` are specified, the badge label will be `app:badgeText`.

### Talkback Support
Expand Down
10 changes: 6 additions & 4 deletions lib/java/com/google/android/material/badge/BadgeDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public void updateBadgeCoordinates(
private boolean isAnchorViewWrappedInCompatParent() {
View customBadgeAnchorParent = getCustomBadgeParent();
return customBadgeAnchorParent != null
&& customBadgeAnchorParent.getId() == R.id.mtrl_anchor_parent;
&& customBadgeAnchorParent.getId() == R.id.mtrl_anchor_parent;
}

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

/** Clears the badge's number. */
public void clearNumber() {
state.clearNumber();
onNumberUpdated();
if (state.hasNumber()) {
state.clearNumber();
onNumberUpdated();
}
}

private void onNumberUpdated() {
Expand Down Expand Up @@ -1414,7 +1416,7 @@ private String getTextBadgeText() {

text = text.substring(0, maxCharacterCount - 1);
return String.format(
context.getString(R.string.m3_exceed_max_badge_text_suffix),
context.getString(R.string.mtrl_exceed_max_badge_text_suffix),
text,
DEFAULT_EXCEED_MAX_BADGE_TEXT_SUFFIX);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
-->

<resources>
<!-- Not used. Kept for backward compatibility -->
<integer name="mtrl_badge_max_character_count">4</integer>
<integer name="m3_badge_max_number">999</integer>

<integer name="mtrl_badge_max_number">999</integer>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
-->
<resources xmlns:tools="http://schemas.android.com/tools"
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="mtrl_exceed_max_badge_text_suffix" translatable="false"><xliff:g example="Some te" id="part of a long text">%1$s</xliff:g><xliff:g example="…" id="suffix">%2$s</xliff:g></string>
<string name="mtrl_exceed_max_badge_number_suffix" translatable="false"><xliff:g example="999" id="maximum number">%1$d</xliff:g><xliff:g example="+" id="suffix">%2$s</xliff:g></string>
<string name="mtrl_exceed_max_badge_number_content_description" tools:ignore="PluralsCandidate"
description="Plural form content description for when the number of new notifications exceeds a maximum count[CHAR_LIMIT=NONE]">More than <xliff:g example="999" id="maximum number">%1$d</xliff:g> new notifications</string>
Expand All @@ -26,7 +27,4 @@
<item quantity="one"><xliff:g id="count">%d</xliff:g> new notification</item>
<item quantity="other"><xliff:g id="count">%d</xliff:g> new notifications</item>
</plurals>

<string name="m3_exceed_max_badge_text_suffix" translatable="false"><xliff:g example="Some te" id="part of a long text">%1$s</xliff:g><xliff:g example="…" id="suffix">%2$s</xliff:g></string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<item name="badgeWithTextHeight">@dimen/mtrl_badge_with_text_size</item>
<item name="badgeWidePadding">@dimen/mtrl_badge_long_text_horizontal_padding</item>
<item name="backgroundColor">?attr/colorError</item>
<item name="maxNumber">999</item>
<item name="maxNumber">@integer/mtrl_badge_max_number</item>
<item name="badgeGravity">TOP_END</item>
<item name="offsetAlignmentMode">legacy</item>
<item name="badgeTextAppearance">@style/TextAppearance.MaterialComponents.Badge</item>
Expand Down