Android Toolbar Adding Menu Items for different fragments

后端 未结 10 1649
野性不改
野性不改 2020-11-28 22:51

I have a toolbar as well as a navigation drawer. When I start my app, the toolbar and navigation drawer are created. When I click items in the navigation drawer, it starts n

10条回答
  •  一整个雨季
    2020-11-28 23:26

    This is how to create menu dynamically: http://www.101apps.co.za/index.php/articles/using-toolbars-in-your-apps.html

    Edited:

    Toolbar actionBarToolBar = (Toolbar) findViewById(R.id.my_toobar);
    setSupportActionBar(actionBarToolBar);
    actionBarToolBar.setNavigationIcon(R.drawable.icon);
    actionBarToolBar.setNavigationContextDescription(getResources().getString(R.string.desc);
    actionBarToolBar.setLogo(R.drawable.other_icon);
    actionBarToolBar.setLogoDescription(getResources().getString(R.string.other_desc);
    actionBarToolBar.inflateMenu(R.menu.fragment_menu);
    

提交回复
热议问题