Changing/removing items of Bottom bar in android
Asked Answered
T

1

5

I have an activity with a BottomNavigationView, I need to switch items (remove old and add new ones) of my bottomNavigationView when a button is clicked. I tried all these options but none of them is working:

 bottomNavigationView.getMenu().clear();
   bottomNavigationView.getMenu().getItem(0).setVisible(false);
   bottomNavigationView.getMenu().removeItem(0);       bottomNavigationView.removeViewInLayout(bottomNavigationView.findViewById(R.id.explore_item));

I tried using the roughike bottom bar and could find a way to switch bottom bar items with a click.

I ended up implementing the worst solution : adding two BottomNavigationViews and switching their visibilty ! The problem is I need to switch bottom bar items more than once, and I cant keep adding bottomNavViews to my ui !

Any help with switching bottom bar items on a button click would appreciated. Thanks.

Thallium answered 27/12, 2016 at 11:41 Comment(3)
Maybe just change icon and listener instead removing and inserting items?Lamination
might be a solution yes , tried it out and it's working. ! But I need to find why none of the code of listed is working..Thallium
Accept answer please if it correct or comment itPomander
A
20

The only solution I found was to use

bottomNavigationView.getMenu().removeItem(R.id.menu_item);
Acquah answered 13/1, 2017 at 13:30 Comment(1)
when i did this, it then alligned the rest of the items in the middle instead of spreading them out againBackflow

© 2022 - 2024 — McMap. All rights reserved.