Highlighting a menu item in BottomNavigationView without invoking onNavigationItemSelected method

假装没事ソ 提交于 2019-12-02 05:48:35

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/45062620/highlighting-a-menu-item-in-bottomnavigationview-without-invoking-onnavigationit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!