Set selected item in Android BottomNavigationView

前端 未结 21 2322
谎友^
谎友^ 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:58

    Just adding another way to perform a selection programatically - this is probably what was the intention in the first place or maybe this was added later on.

    Menu bottomNavigationMenu = myBottomNavigationMenu.getMenu();
    bottomNavigationMenu.performIdentifierAction(selected_menu_item_id, 0);
    

    The performIdentifierAction takes a Menu item id and a flag.

    See the documentation for more info.

提交回复
热议问题