android - Change actionbar menu in fragment -


I want to load another menu XML while loading the piece. I am using this code in the main activity:

  @Orride Creative Options menu on the Public Boolean menu (menu menu) {getMenuInflater (). Flowers (menus menu, menus); Back true; }  

I am using this code in a piece:

  @Override Creates the public at zero (bundled saved instenstate) {super.onCreate ( SavedInstanceState); SetHasOptionsMenu (true); } Override public zero on @CreateOptionsMenu (menu menus, menu infletter info) {getActivity () GetMenuInflater () Flood (R. menu framemart menu, menu); Super.onCreateOptionsMenu (menu, inflater); }  

When the user loads the piece, then the activity menu should be removed, then the fragment menu should be loaded onto the action. And when the user clicks on the back button from the piece of the piece, then the pieces menu should be removed, the main activity menu should be loaded in the action bar.

Now the code is not removing the old menu, it is adding new menus to the old menu.

I

Code> menu.clear (); method.

This removes all existing items from the menu, except as it is now created.

Try it ..

  @OrrideCarateOptionsMenu Public Zero (menu menu, MenuInflater inflater) {menu.clear (); // clears all menu items .. getActivity () GetMenuInflater () Flood (R.menu.fragment_menu, menu); Super.onCreateOptionsMenu (menu, inflater); }  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -