Hide MenuItem in some Fragments

后端 未结 13 2141
南方客
南方客 2020-12-07 20:00

I using menu drawer which has more Fragments. In some Fragments I have menu item REFRESH but in some fragments I want hide this menu item (I don\'t

13条回答
  •  失恋的感觉
    2020-12-07 20:31

    Firstly in your Activity that has the toolbar, create a method that sets up the overflow menu for you:

    public void setUpOptionMenu(Toolbar toolbar){
        this.setSupportActionBar(toolbar);
    }
    

    In your fragments onCreateView() method, get the reference of your current activity and call your activities setUpOptionMenu() method:

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        ...
        ...
        public void ((YourActivityName)this.getActivity()).setUpOptionMenu(null);
        ...
        ...
    }
    

    Cheers!!!

提交回复
热议问题