Android - How to hide menu option for current fragment

前端 未结 6 1483
执笔经年
执笔经年 2021-01-12 20:39

I have an ActionBar activity with a FrameLayout and a menu. when the user clicks the menu item I replace the fragment with the relevant new fragment. However, I cannot see a

6条回答
  •  生来不讨喜
    2021-01-12 21:23

    First get the item you want to remove :

    MenuItem item = menu.findItem(R.id.your_action);
    

    then set it's Visibility false :

    item.setVisible(false);
    

    and if the problem is in getting the menu (as it's not in the fragment), you can easily get a context from the activity that contains the menu and get the menu by it.

提交回复
热议问题