Skip to content

Commit d3e76d3

Browse files
wcshihunterstich
authored andcommitted
Alleviate badge being clipped off by calling setClipChildren(false) and setClipToPadding(false) on a tabview's parent.
If a long badge is shown on an end tab with a long string, it could still be clipped off. Current workaround is to adjust the badge offset. Resolves #1168 PiperOrigin-RevId: 305686535
1 parent d5fc3fd commit d3e76d3

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/java/com/google/android/material/tabs/TabLayout.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ public class TabLayout extends HorizontalScrollView {
358358
public @interface TabIndicatorGravity {}
359359

360360
/** Callback interface invoked when a tab's selection state changes. */
361-
public interface OnTabSelectedListener extends BaseOnTabSelectedListener<Tab> {
362-
}
361+
public interface OnTabSelectedListener extends BaseOnTabSelectedListener<Tab> {}
363362

364363
/**
365364
* Callback interface invoked when a tab's selection state changes.
@@ -2664,9 +2663,7 @@ private void tryAttachBadgeToAnchor(@Nullable View anchorView) {
26642663
return;
26652664
}
26662665
if (anchorView != null) {
2667-
// Avoid clipping a badge if it's displayed.
2668-
setClipChildren(false);
2669-
setClipToPadding(false);
2666+
clipViewToPaddingForBadge(false);
26702667
BadgeUtils.attachBadgeDrawable(
26712668
badgeDrawable, anchorView, getCustomParentForBadge(anchorView));
26722669
badgeAnchorView = anchorView;
@@ -2677,16 +2674,26 @@ private void tryRemoveBadgeFromAnchor() {
26772674
if (!hasBadgeDrawable()) {
26782675
return;
26792676
}
2677+
clipViewToPaddingForBadge(true);
26802678
if (badgeAnchorView != null) {
2681-
// Clip children / view to padding when no badge is displayed.
2682-
setClipChildren(true);
2683-
setClipToPadding(true);
26842679
BadgeUtils.detachBadgeDrawable(
26852680
badgeDrawable, badgeAnchorView, getCustomParentForBadge(badgeAnchorView));
26862681
badgeAnchorView = null;
26872682
}
26882683
}
26892684

2685+
private void clipViewToPaddingForBadge(boolean flag) {
2686+
// Avoid clipping a badge if it's displayed.
2687+
// Clip children / view to padding when no badge is displayed.
2688+
setClipChildren(flag);
2689+
setClipToPadding(flag);
2690+
ViewGroup parent = (ViewGroup) getParent();
2691+
if (parent != null) {
2692+
parent.setClipChildren(flag);
2693+
parent.setClipToPadding(flag);
2694+
}
2695+
}
2696+
26902697
final void updateOrientation() {
26912698
setOrientation(inlineLabel ? HORIZONTAL : VERTICAL);
26922699
if (customTextView != null || customIconView != null) {

0 commit comments

Comments
 (0)