Is there a way to display notification badge on Google's official BottomNavigationView menu items introduced in API 25?

前端 未结 3 1972
野性不改
野性不改 2020-12-31 10:49

I have been trying BottomNavigationView released in API 25. I want to display a notification badge (say a small blue circle with or without a count in it) on on

3条回答
  •  不思量自难忘°
    2020-12-31 11:28

    One way of achieving this is using two icons for each item - one with the badge and the other without and replace them programmatically. Alternatively, instead of two icons, you can use a single icon and draw the badge programmatically. So the code can look something like this (assuming you know the index of each item and can get the Drawable for each):

    public static void updateItem(BottomNavigationView bottomNavigationView, int index, Drawable icon) {
        Menu menu = bottomNavigationView.getMenu();
        MenuItem item = menu.getItem(index);
    
        if (item != null) {
            item.setIcon(icon);
        }
    }
    

提交回复
热议问题