How to Set selected item in BottomNavigationView

前端 未结 12 1854
半阙折子戏
半阙折子戏 2020-12-25 11:48

I am trying to set default item on activity created but it isn\'t working? This is my code:

protected void onCreate(Bundle savedInstanceState) {
    super.o         


        
12条回答
  •  孤城傲影
    2020-12-25 12:06

    There are two senario

    Set the selected menu item ID. This behaves the same as tapping on an item.

    Code example:

    BottomNavigationView bottomNavigationView;
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavigationView);
    bottomNavigationView.setOnNavigationItemSelectedListener(myNavigationItemListener);
    bottomNavigationView.setSelectedItemId(R.id.my_menu_item_id);
    

    I you only need to check it without tapping

    Code example:

      BottomNavigationView bottomNavigationView= (getActivity()).findViewById(R.id.bottom_navigation);
        bottomNavigationView.getMenu().findItem(R.id.action_manage_orders_id).setChecked(true);
    

提交回复
热议问题