android getMenuInflater() in a fragment subclass - cannot resolve method

后端 未结 4 729
萌比男神i
萌比男神i 2021-02-07 19:32

I am trying to inflate a menu in a class that inherits the Fragment class. Here is my OnCreateOptionsMenu() method -

@Override
public bo         


        
4条回答
  •  暖寄归人
    2021-02-07 20:15

    In your fragment class add:

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.[IDMENU], menu) ;
    }
    

    Where [IDMENU] is the XML name of your menu.

    Next you need to add inside onCreate or onCreateView method this:

    setHasOptionsMenu(true);
    

提交回复
热议问题