I am trying to use the BottomNavigationView from a design library. Everything works, except that each navigation element starts working, and so I want to remove all elements on nav so that they look the same. I tried several solutions, most of which do not work, and the last one works, but feels very hacked.
First I did this:
ViewGroup nav = (ViewGroup) bottomNav; for(int i=0; i < nav.getChildCount(); i++) { nav.getChildAt(i).setSelected(false); }
Which seemed to do nothing.
Then I tried:
int size = bottomNav.getMenu().size(); for (int i = 0; i < size; i++) { bottomNav.getMenu().getItem(i).setChecked(false); }
which only last checked the element, not the first.
And finally, I tried adding a dummy element to the menu and doing:
bottomNav.getMenu().findItem(R.id.dummmy_item).setChecked(true); bottomNav.findViewById(R.id.dummmy_item).setVisibility(View.GONE);
Which almost works, but hides the title below it, which is important for the context in my case.
Then, I found this answer: https://stackoverflow.com/a/165454/ ... and edited my solution above to include it. In particular, I added a proguard rule, and I used this exact helper class and named the method. It looks right, it seems to work. But it’s very bad for me, because:
- I use a dummy menu item so that no visible items are visible.
- It adds quite a bit of code for what should be a small visual fix.
- I read before this reflection should be avoided, if at all possible.
Is there any other, preferred, simpler way to achieve this, or is this the best we have with the current version of the library?
(As a remark, I wonder if the proguard rule is needed in this solution and what it does? I don't know anything about proguard, but this project is inherited from someone who included it).