How to programmatically add a submenu item to the new material design android support library

前端 未结 5 1582
时光说笑
时光说笑 2020-11-28 23:26

I am trying to add new menu items to a submenu in the new Material Design drawer panel.



        
5条回答
  •  野性不改
    2020-11-29 00:08

    I found easier way to change navigation view ( work with both submenu and menu). You can re-inflate NavigationViewat runtime with 2 lines of code. In this example, I re-inflate new_navigation_drawer_items.xml using public method inflateMenu (You can create a menu xml file with your new submenu)

    navigationView.getMenu().clear(); //clear old inflated items.
    navigationView.inflateMenu(R.menu.new_navigation_drawer_items); //inflate new items.
    

提交回复
热议问题