Skip to content

Commit 7628351

Browse files
committed
[Badge][Toolbar] Fix issue where menu item content description is not reset after clearing badge content
PiperOrigin-RevId: 675531679
1 parent 35cc084 commit 7628351

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private static void attachBadgeContentDescription(
149149
public void onInitializeAccessibilityNodeInfo(
150150
View host, AccessibilityNodeInfoCompat info) {
151151
super.onInitializeAccessibilityNodeInfo(host, info);
152-
info.setContentDescription(badgeDrawable.getContentDescription());
152+
info.setContentDescription(getBadgeAnchorContentDescription(view, badgeDrawable));
153153
}
154154
});
155155
} else {
@@ -160,12 +160,20 @@ public void onInitializeAccessibilityNodeInfo(
160160
public void onInitializeAccessibilityNodeInfo(
161161
View host, AccessibilityNodeInfoCompat info) {
162162
super.onInitializeAccessibilityNodeInfo(host, info);
163-
info.setContentDescription(badgeDrawable.getContentDescription());
163+
info.setContentDescription(getBadgeAnchorContentDescription(view, badgeDrawable));
164164
}
165165
});
166166
}
167167
}
168168

169+
private static CharSequence getBadgeAnchorContentDescription(
170+
View anchor, BadgeDrawable badgeDrawable) {
171+
CharSequence badgeContentDescription = badgeDrawable.getContentDescription();
172+
return badgeContentDescription != null
173+
? badgeContentDescription
174+
: anchor.getContentDescription();
175+
}
176+
169177
/**
170178
* Detaches a BadgeDrawable from its associated anchor. The BadgeDrawable will be removed from its
171179
* anchor's ViewOverlay. If it has a FrameLayout custom parent that is an ancestor of the anchor,
@@ -213,7 +221,7 @@ private static void detachBadgeContentDescription(@NonNull View view) {
213221
public void onInitializeAccessibilityNodeInfo(
214222
View host, AccessibilityNodeInfoCompat info) {
215223
super.onInitializeAccessibilityNodeInfo(host, info);
216-
info.setContentDescription(null);
224+
info.setContentDescription(view.getContentDescription());
217225
}
218226
});
219227
} else {

0 commit comments

Comments
 (0)