Search code examples
androidbottomnavigationview

How to dynamically hide a menu item in BottomNavigationView?


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

mBottomNavigationView.getMenu()
            .findItem(R.id.item_name)
            .setVisible(false);

mBottomNavigationView.invalidate();

Solution

  • mBottomNavigationView.getMenu().removeItem(R.id.item_name);
    

    removeItem does the trick. Not sure why setVisible method is not working.