Android Toolbar Adding Menu Items for different fragments

后端 未结 10 1658
野性不改
野性不改 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:35

    The simplest option is to do

    toolbar.inflateMenu(R.menu.fragment_menu);
    

    and for handle click on menu item

    toolbar.setOnMenuItemClickListener {
        when (it.itemId) {
            R.id.nav_example -> doThat()
        }
        true
    }
    

提交回复
热议问题