I have a BottomNavigationView in my activity with onNavigationItemSelected listener.
I have two questions:
Does setSelectedItemId method invoke the onNavigationItemSelected method? The documentation says this method behaves as if the menu item was tapped, my observation is yes.
If yes, how to highlight a menu item without invoking onNavigationItemSelected?
Yes, BottomNavigationView.setSelectedItemId(int itemId) triggers onNavigationItemSelected(MenuItem item).
Use BottomNavigationView.getMenu().getItem(int index) or BottomNavigationView.getMenu().findItem(int id), then call MenuItem.setChecked(boolean checked) to highlight a menu item without triggering onNavigationItemSelected(MenuItem item).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With