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

本小妞迷上赌 提交于 2019-12-03 10:29:22

问题


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)

回答1:


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



来源:https://stackoverflow.com/questions/26789315/how-do-you-remove-an-inflated-menu-items-from-the-new-lollipop-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!