Skip to content

Commit 6cb11c8

Browse files
wcshidsn5ft
authored andcommitted
Update TabLayout documentation to add badge section.
PiperOrigin-RevId: 250510447
1 parent 6e250a6 commit 6cb11c8

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

docs/components/TabLayout.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,34 @@ Alternatively, you can add a `TabLayout` to a ViewPager in XML:
8989
</androidx.viewpager.widget.ViewPager>
9090
```
9191

92+
### Badges
93+
94+
![TabLayout with badges](assets/tablayout-badges.png)
95+
96+
`TabLayout` supports displaying icon and number badges.
97+
98+
Initializes and shows a BadgeDrawable associated with a tab. Subsequent calls to
99+
this method will reuse the existing BadgeDrawable.
100+
101+
```java
102+
BadgeDrawable badge = tablayout.getTab(0).showBadge();
103+
// Optionally show a number.
104+
badge.setNumber(99);
105+
```
106+
107+
NOTE: Don't forget to remove any BadgeDrawables that are no longer needed.
108+
109+
```java
110+
tablayout.getTab(0).removeBadge();
111+
```
112+
113+
Best Practice: If you only need to temporarily hide the badge(e.g. until the
114+
next notification is received), the recommended/lightweight alternative is to
115+
change the visibility of the BadgeDrawable instead.
116+
117+
Please see [`BadgeDrawable`](BadgeDrawable.md) for details on how to update the
118+
badge content being displayed.
119+
92120
### Material Styles
93121

94122
Using `TabLayout` with an updated Material theme (`Theme.MaterialComponents`)
18.3 KB
Loading

0 commit comments

Comments
 (0)