Java Code Examples for com.google.android.material.bottomnavigation.BottomNavigationView#getBadge()

The following examples show how to use com.google.android.material.bottomnavigation.BottomNavigationView#getBadge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BottomNavigationDemoFragment.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void clearAndHideBadge(int menuItemId) {
  for (BottomNavigationView bn : bottomNavigationViews) {
    MenuItem menuItem = bn.getMenu().getItem(0);
    if (menuItem.getItemId() == menuItemId) {
      // Hide instead of removing the badge associated with the first menu item because the user
      // can trigger it to be displayed again.
      BadgeDrawable badgeDrawable = bn.getBadge(menuItemId);
      if (badgeDrawable != null) {
        badgeDrawable.setVisible(false);
        badgeDrawable.clearNumber();
      }
    } else {
      // Remove the badge associated with this menu item because cannot be displayed again.
      bn.removeBadge(menuItemId);
    }
  }
}
 
Example 2
Source File: BottomNavigationDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void updateBadgeGravity(@BadgeGravity int badgeGravity) {
  for (BottomNavigationView bn : bottomNavigationViews) {
    for (int i = 0; i < MAX_BOTTOM_NAV_CHILDREN; i++) {
      // Update the badge gravity on all the menu items.
      MenuItem menuItem = bn.getMenu().getItem(i);
      int menuItemId = menuItem.getItemId();
      BadgeDrawable badgeDrawable = bn.getBadge(menuItemId);
      if (badgeDrawable != null) {
        badgeDrawable.setBadgeGravity(badgeGravity);
      }
    }
  }
}