Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlighting a menu item in BottomNavigationView without invoking onNavigationItemSelected method

I have a BottomNavigationView in my activity with onNavigationItemSelected listener.

I have two questions:

  1. Does setSelectedItemId method invoke the onNavigationItemSelected method? The documentation says this method behaves as if the menu item was tapped, my observation is yes.

  2. If yes, how to highlight a menu item without invoking onNavigationItemSelected?

like image 677
Falak Marri Avatar asked Jul 12 '17 15:07

Falak Marri


1 Answers

  1. Yes, BottomNavigationView.setSelectedItemId(int itemId) triggers onNavigationItemSelected(MenuItem item).

  2. 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).

like image 165
Nathan Reline Avatar answered Oct 13 '22 23:10

Nathan Reline