How to dynamically hide a menu item in BottomNavigationView?

后端 未结 9 1548
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 20:04

I want to hide a menu item of BottomNavigationView dynamically based on some conditions. I tried the following but it is not working.

mBottomNavigationView.g         


        
9条回答
  •  一整个雨季
    2020-12-30 20:33

    The removeItem displaces the menu items in the bar when an item(s) is hidden. I found a slightly better way. Create a group of menu items that you would want to hide your menu xml.

    In your bottom_menu.xml

    
        
            
            
        
        
    
    

    And in your activity.cs

    Menu menu = mbottomNavigation.getMenu();  
    menu.setGroupEnabled(R.id.hiddenmenu, false);
    

    Although, with this setup, when all menu items are visible, the checked change state of the menu items goes out of whack. Also tried programmatically adding menu items to an empty group but the group stopped responding to the GroupDisable...

提交回复
热议问题