Android - How to hide menu option for current fragment

前端 未结 6 1485
执笔经年
执笔经年 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:16

    In the fragment where you want to hide the Item

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        MenuItem item=menu.findItem(R.id.action_search);
        item.setVisible(false);
    

    and in onCreate() of your fragment

     setHasOptionsMenu(true);
    

提交回复
热议问题