Skip to content

Commit a9f135b

Browse files
wcshidsn5ft
authored andcommitted
Only set clipPadding and clipChildren to false when BottomNavigationItemView is going to display a badge.
PiperOrigin-RevId: 249981675
1 parent c7d21ae commit a9f135b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/java/com/google/android/material/bottomnavigation/BottomNavigationItemView.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ public BottomNavigationItemView(@NonNull Context context, AttributeSet attrs) {
8787
public BottomNavigationItemView(Context context, AttributeSet attrs, int defStyleAttr) {
8888
super(context, attrs, defStyleAttr);
8989
final Resources res = getResources();
90-
// Avoid clipping a badge if it's displayed.
91-
setClipChildren(false);
92-
setClipToPadding(false);
9390

9491
LayoutInflater.from(context).inflate(R.layout.design_bottom_navigation_item, this, true);
9592
setBackgroundResource(R.drawable.design_bottom_navigation_item_background);
@@ -432,6 +429,10 @@ private void tryAttachBadgeToAnchor(View anchorView) {
432429
return;
433430
}
434431
if (anchorView != null) {
432+
// Avoid clipping a badge if it's displayed.
433+
setClipChildren(false);
434+
setClipToPadding(false);
435+
435436
BadgeUtils.attachBadgeDrawable(
436437
badgeDrawable, anchorView, getCustomParentForBadge(anchorView));
437438
}
@@ -442,6 +443,10 @@ private void tryRemoveBadgeFromAnchor(View anchorView) {
442443
return;
443444
}
444445
if (anchorView != null) {
446+
// Clip children / view to padding when no badge is displayed.
447+
setClipChildren(true);
448+
setClipToPadding(true);
449+
445450
BadgeUtils.detachBadgeDrawable(
446451
badgeDrawable, anchorView, getCustomParentForBadge(anchorView));
447452
}

0 commit comments

Comments
 (0)