Android - How to hide menu option for current fragment

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

    Add below codes into your fragment

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }
    
    public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        MenuItem item = menu.findItem(R.id.save);
        item.setVisible(false);
    }
    

提交回复
热议问题