Search code examples
androidandroid-layoutkotlinbottomnavigationviewmaterial-components-android

Badge on bottomNavigationView padding or margin


How can we set margin to badge of bottomNavigation material component??

OR

How can we prevent to padding when we click on an item in bottomNavigationView because of that a little of badge will be hidden as we see in these pictures.

When item 1 is unSelected :

enter image description here

When item 1 isSelected (a little of badge height will be hidden):

enter image description here


Solution

  • You can use the method setVerticalOffset:

      BadgeDrawable badge = bottomNavigationView.getOrCreateBadge(menuItemId);
      badge.setNumber(...);
      badge.setVerticalOffset(20);  //The dimension is in pixel
    

    Before:

    enter image description here

    After:

    enter image description here

    If it covers the icon you can also use the method setHorizontalOffset:

    badge.setHorizontalOffset(-10);
    

    enter image description here

    Note: it requires at least the version 1.2.0-alpha01