如何从新的Lollipop工具栏中删除膨胀的菜单/项目? [英] How do you remove an inflated menu/items from the new Lollipop Toolbar?
本文介绍了如何从新的Lollipop工具栏中删除膨胀的菜单/项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在版式中包含一个v7工具栏.
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:
- 夸大一个空菜单
-
mToolbar.inflateMenu(0)
-
moolbar.setMenu(null, null)
-
toolbar.setMenu(null, null)
- inflating an empty menu
mToolbar.inflateMenu(0)
moolbar.setMenu(null, null)
toolbar.setMenu(null, null)
推荐答案
我不确定这是否是您的意思,也没有尝试过.
I am not entirely sure if this is what you mean nor have tried it but.
mToolbar.getMenu().clear();
应清除菜单.
尽管如此,我仍在使用onCreateOptionsMenu
进行所有菜单创建
I have still been using onCreateOptionsMenu
for all my menu creation however
这篇关于如何从新的Lollipop工具栏中删除膨胀的菜单/项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文