How to set notification count for Android BottomNavigationView?

前端 未结 4 1477
礼貌的吻别
礼貌的吻别 2021-02-03 12:59

I am using

 

to set BottomNavigationView in my android app. My question is

4条回答
  •  猫巷女王i
    2021-02-03 13:31

    Create a layout with one Textview like below.

    
    
        
    
    
    

    After initializing the BottomNavgationView, you have to inflate the layout and select the index of View item and set the count.

        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
        BottomNavigationMenuView bottomNavigationMenuView =
                (BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
        View v = bottomNavigationMenuView.getChildAt(1);
        BottomNavigationItemView itemView = (BottomNavigationItemView) v;
    
        View badge = LayoutInflater.from(this)
                .inflate(R.layout.homescreen_count, bottomNavigationMenuView, false);
        TextView tv = badge.findViewById(R.id.notification_badge);
        tv.setText("22+");
        itemView.addView(badge);
    

提交回复
热议问题