强制在Android溢出菜单按钮 [英] Forcing Overflow menu button on Android
问题描述
我正在开发针对Android 4.0.3的应用程序。我有多个片段,我有一个菜单项显示在他们每个人。我想有一个溢出菜单按钮,将有2个菜单项。如何强制溢出菜单的外观,并添加菜单项呢?我通过调用每个片段onCreateOptionsMenu功能添加菜单项。
I am developing an application for Android 4.0.3. I have multiple fragments and I have one menu item displayed on each of them. I want to have an overflow menu button that will have 2 menu items. How do I force the appearance of the overflow menu and add menu items to it ? I am adding menu items by calling the onCreateOptionsMenu function in each fragment.
任何和所有帮助将是AP preciated。谢谢!
Any and all help would be appreciated. Thanks!
推荐答案
要强行进入溢出菜单中做到这一点:
To force into the overflow menu do this:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add(0, 2, 0, "Item 1").setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
return true;
}
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
将迫使项目进入任一:
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
will force the item into either:
安卓3.0 +:在动作条为溢出 Android 2.3的 - :菜单按钮
Android 3.0 + : The ActionBar as an overflow Android 2.3 - : The menu button
如果你是想重新创建菜单中,您将需要调用 invalidateOptionsMenu();
从 OnCreateOptionsMenu $ C这将重新创建$ C>。
If you are wanting to recreate the menu you will need to call invalidateOptionsMenu();
This will re-create from OnCreateOptionsMenu
.
这篇关于强制在Android溢出菜单按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!