How to create the custom item of Bottomnavigationview Android?

前端 未结 3 1134
长情又很酷
长情又很酷 2021-02-08 14:30

I am using the Bottomnavigationview for tab-bar in my application, for it, i am using the following code.Please check it once.

Layout :-

3条回答
  •  情书的邮戳
    2021-02-08 15:25

    I have done the above task as the following approach, please have a look on the solution

    Layout

       /// YOUR MENU ITEMS FOR THE BOTTOM NAVIGATION
    

    Your badge count layout be like below

    
    
    
        
    
    

    And than after your badge drawable be like below

    
    
        
        
    
    

    And at the last, you need we need to inflate our badge layout into our MainActivity.java , where we use the BottomNavigationView, please check the following code for it.

        BottomNavigationMenuView mbottomNavigationMenuView =
                (BottomNavigationMenuView) mBinding.bottomNavigation.getChildAt(0);
    
        View view = mbottomNavigationMenuView.getChildAt(4);
    
        BottomNavigationItemView itemView = (BottomNavigationItemView) view;
    
        View cart_badge = LayoutInflater.from(this)
                .inflate(R.layout.profile_view,
                        mbottomNavigationMenuView, false);
    
        //// AND THAN SET THE COUNTER BADGE, AS FOLLOW
        ((TextView) cart_badge.findViewById(R.id.notificationsBadge)).setText("5");
    
        itemView.addView(cart_badge);
    

提交回复
热议问题