How do you remove an inflated menu/items from the new Lollipop Toolbar?

AndroidAndroid MenuAndroid Toolbar

Android Problem Overview


I include a v7 Toolbar in my layout.

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    />

I'm inflating a menu into it with the following:

mToolbar.inflateMenu(R.menu.options_add_contact);

Now how do I know remove/reset it? I've tried a couple shots in the dark:

  • inflating an empty menu
  • mToolbar.inflateMenu(0)
  • moolbar.setMenu(null, null)
  • toolbar.setMenu(null, null)

Android Solutions


Solution 1 - Android

I am not entirely sure if this is what you mean nor have tried it but.

mToolbar.getMenu().clear();

should clear the menu.

I have still been using onCreateOptionsMenu for all my menu creation however

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionloeschgView Question on Stackoverflow
Solution 1 - AndroidtyczjView Answer on Stackoverflow