Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of BottomNavigationView badge background?

I have implemented BottomNavigationView with badge count based on this example https://stackoverflow.com/a/56340643/6699103

it works fine but I wanted to change the background color for badge Is there any way to do that?

like image 647
Zero Cool Avatar asked Oct 22 '19 12:10

Zero Cool


Video Answer


1 Answers

Just use the method setBackgroundColor() of the badge.

  BadgeDrawable badge = bottomNavigationView.getOrCreateBadge(menuItemId);
  badge.setNumber(..);
  badge.setBackgroundColor(....);

enter image description here

If you want to change globally in your app the style you can define the badgeStyle attr in your app theme:

<style name="AppTheme" parent="Theme.MaterialComponents.*">
  <item name="badgeStyle">@style/CustomBadge</item>
  ...
</style>

<style name="CustomBadge" parent="@style/Widget.MaterialComponents.Badge">
   <item name="backgroundColor">@color/.....</item>
</style>
like image 162
Gabriele Mariotti Avatar answered Oct 08 '22 01:10

Gabriele Mariotti