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

后端 未结 4 726
萌比男神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:02

    The signature of your onCreateOptionsMenu doesn't look right. Take a look at the docs here

    Take a look this code

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);//Make sure you have this line of code.
    }
    
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // TODO Add your menu entries here
        super.onCreateOptionsMenu(menu, inflater);
    }
    

提交回复
热议问题