invalidateOptionsMenu doesn't work in fragment

前端 未结 3 524
梦毁少年i
梦毁少年i 2021-02-04 00:44

I want to show or hide item in actionbar according to either their is text in the edit text or not

so I did the following

            public class Noun         


        
3条回答
  •  忘了有多久
    2021-02-04 01:44

    Solution 1

    This is work in fragment

     getActivity().invalidateOptionsMenu();
    

    Solution 2

    Try this if above code is not working

    invalidateOptionsMenu(getActivity());
    

    Import this library

    import static androidx.core.app.ActivityCompat.invalidateOptionsMenu;
    

提交回复
热议问题