Trying to hide and show menu items on action bar

后端 未结 4 992
灰色年华
灰色年华 2021-02-05 19:26

I have looked through the questions on stack overflow and can\'t find the solution.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater i         


        
4条回答
  •  日久生厌
    2021-02-05 20:30

    Try this,

    private Menu menu=null;
    @Override
    public void onCreateOptionsMenu(Menu menu,MenuInflater inflater)
    {
        inflater.inflate(R.menu.note_menu, menu);
        this.menu=menu;
    super.onCreateOptionsMenu(menu,inflater);
    menu.findItem(R.id.menuChartNoteEdit).setVisible(isdown);
    menu.findItem(R.id.menuChartOpenNote).setVisible(isdown);
    }
    

    When you want to hide menu at any where, after executing onCreateOptionsMenu() then just change value for isdown and repeat this code,

    menu.findItem(R.id.menu_settings).setVisible(isdown);
    menu.findItem(R.id.menu_save).setVisible(isdown);
    

提交回复
热议问题