Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore BottomNavigationView state? [duplicate]

I'm wondering how one could restore the state of a BottomNavigationView (android.support.design.widget.BottomNavigationView).

I tried to call bottomNavigationView.getMenu().findItem(restoredItemId).setChecked(true); but this does not result in a correct state inside BottomNavigationView, it only highlights the found item.

I also found below methods, but those don't seem to help much:

((BottomNavigationMenu) bottomNavigationView.getMenu()).savePresenterStates(state);
((BottomNavigationMenu) bottomNavigationView.getMenu()).saveActionViewStates(state);

((BottomNavigationMenu) bottomNavigationView.getMenu()).restorePresenterStates(state);
((BottomNavigationMenu) bottomNavigationView.getMenu()).restoreActionViewStates(state);
like image 560
Markus Rubey Avatar asked Mar 07 '26 04:03

Markus Rubey


1 Answers

I've used the code below to select item programmatically:

View view = bottomNavigationView.findViewById(R.id.menu_action_dashboard);
view.performClick();

Seems like it should work in your case.

like image 120
UneXp Avatar answered Mar 08 '26 16:03

UneXp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!