How can I get menu item in NavigationView?

后端 未结 5 1726
眼角桃花
眼角桃花 2021-02-05 00:28


        
5条回答
  •  难免孤独
    2021-02-05 01:13

    I think you should first get the menu like this:

    navigationView.getMenu().findItem(R.id.login).setVisible(false);
    

    The main aspect of this code is calling navigationView.getMenu() to get the menu from this you will have a reference of current inflated menu and call findViewById() and after that you can whatever you what.

    For Group of item ex:-

    
    ...
    

    and then you can control this using :-

    navigationView.getMenu().setGroupVisible(R.id.group_1, true)
    

提交回复
热议问题