onPrepareOptionsMenu not getting called in Fragments

后端 未结 4 1302
花落未央
花落未央 2021-01-07 17:34
    @Override
    public void onCreateOptionsMenu(Menu menu,MenuInflater inflater){
        Log.d(\"Does\", \"get called\");
        inflater.inflate(R.menu.menuItem         


        
4条回答
  •  醉话见心
    2021-01-07 18:21

    Probably too late, but I had same problem and the solution was really simple. Just call getActivity().invalidateOptionsMenu() from your fragment. This will call onPrepareOptionsMenu and here you can control the visibility of your items like this: menu.findItem(R.id.youritem).setVisible(true/false); Hope that helps!

提交回复
热议问题