Badge on BottomNavigationView

前端 未结 4 1237
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 02:03

I am trying to add a badge to the BottomNavigationView Item without using any library, however somehow the BottomNavigationView is not showing the

4条回答
  •  旧时难觅i
    2020-12-02 02:36

    You can use the BottomNavigationView provided by the Material Components Library.

    Just add the BottomNavigationView to your layout:

      
    

    Then use in your code:

      int menuItemId = bottomNavigationView.getMenu().getItem(0).getItemId();
      BadgeDrawable badge = bottomNavigationView.getOrCreateBadge(menuItemId);
      badge.setNumber(2);
    

    To change the badge gravity use the setBadgeGravity method.

    badge.setBadgeGravity(BadgeDrawable.BOTTOM_END);
    

提交回复
热议问题