How can I add a menu dynamically to bottom navigation view?

前端 未结 3 665
清酒与你
清酒与你 2020-12-29 06:06

Android has new ui element - BottomNavigationView

I don\'t want to contain my menus in the xml files. I will receive the information about menu items and or

3条回答
  •  暖寄归人
    2020-12-29 06:54

    By default, BottomNavigationView starts with an empty menu. You can use the getMenu() method to get the Menu instance, then add menu items as in the response above. For example,

    BottomNavigationView bottomNavigation = findViewById(R.id.bottom_navigation);
    Menu menu = bottomNavigation.getMenu();
    menu.add(Menu.NONE, MENU_ITEM_ID_ONE, Menu.NONE, getString(R.string.str_menu_one))
        .setIcon(R.drawable.ic_action_one);
    

提交回复
热议问题