Set selected item in Android BottomNavigationView

前端 未结 21 2335
谎友^
谎友^ 2020-11-27 14:16

I am using the new android.support.design.widget.BottomNavigationView from the support library. How can I set the current selection from code? I realized, that

21条回答
  •  难免孤独
    2020-11-27 14:53

    You can try the performClick method :

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

    Edit

    From API 25.3.0 it was introduced the method setSelectedItemId(int id) which lets you mark an item as selected as if it was tapped.

提交回复
热议问题