Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide menu on fragment (which is being replaced from the layout)?

I have checked and tried out all the possible codes here but those didn't work for me as i am replacing the layout only not having different toolbar.I am using fragments and NavigationDrawer, the navigationdrawer has listview, when a listitem is clicked it is replacing the layout with the following fragments. But how do i hide the menu or modify it based on different layout appeard?

like image 400
silverFoxA Avatar asked Apr 16 '15 11:04

silverFoxA


People also ask

How do we hide the menu on toolbar in one fragment?

How do we hide the menu on toolbar in one fragment? When you click the show button to open a fragment, you can see the fragment menu items ordered before activity menu items. This is because of the menu item's android:orderInCategory attribute value. When you click the hide button to hide the fragment.

How do you make a menu item invisible?

Get a MenuItem pointing to such item, call setVisible on it to adjust its visibility and then call invalidateOptionsMenu() on your activity so the ActionBar menu is adjusted accordingly. Save this answer.

How can I hide the whole menu in android?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Full screen gestures”. The navigation bar will be hidden and you will be shown “Gesture demos” to explain how to operate the “Go back”, “Go to Home screen” and “Open Recents” functions.

How do you add remove and replace fragments?

Use replace() to replace an existing fragment in a container with an instance of a new fragment class that you provide. Calling replace() is equivalent to calling remove() with a fragment in a container and adding a new fragment to that same container. transaction. commit();


1 Answers

If you want to control the option menu from Fragment you need to call setHasOptionsMenu in the onCreate of the Fragment:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
}

Then you can add, remove or clear the menu overriding onCreateOptionsMenu. For example this code remove every item in options menu:

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    menu.clear();
}
like image 104
Mattia Maestrini Avatar answered Sep 30 '22 01:09

Mattia Maestrini