调用supportInvalidateOptionsMenu()后,菜单ActionBarActivity无法正常工作; [英] Menu ActionBarActivity not work after calling supportInvalidateOptionsMenu();
问题描述
我与图书馆和抽屉菜单的兼容性工作。
调用supportInvalidateOptionsMenu()函数后;在弹出菜单中没有出现,只留下核心流图标。
这个解决的办法?
为此在我ActMain(非常碎片主要活动)
@覆盖
prepareOptionsMenu(菜单菜单)上公共布尔{ //如果资产净值抽屉被打开,隐藏操作项相关内容视图
布尔drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
hideMenuItems(菜单,drawerOpen!);
返回super.on prepareOptionsMenu(菜单);
} 私人无效hideMenuItems(菜单菜单,布尔可见)
{ 的for(int i = 0; I< menu.size();我++){ menu.getItem(ⅰ).setVisible(可见);
}
}
请注意:只有一个有子菜单项。在这个子菜单中,所有
项目是可见的,但是当我点击即出现在项目
在ActionBar其他项目,他们根本不会出现一个以上的
时间。这仅发生在的Android 2.3版本。在上部作品
好。
块引用>解决方案的
supportInvalidateOptionsMenu
仅适用于Android 2.3及更低
这就是为什么它有一个preFIX支持
就可以了,更容易,如果你使用了上prepareOptionsMenu
为不叫当你试图在Android 2.3及以上
。解决方案:
您可以先检查设备是否
2.3和更低
或上方
,如果是的上方使用invalidateOptionsMenu()
更新/调用上prepareOptionsMenu
I'm working with the library and compatibility with Drawer menu.
After calling the supportInvalidateOptionsMenu () function; the popup menu fails to appear, leaving only the core flow icon.
Any solution for this?
Do this in my ActMain (main activity for very fragments)
@Override public boolean onPrepareOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); hideMenuItems(menu, !drawerOpen); return super.onPrepareOptionsMenu(menu); } private void hideMenuItems(Menu menu, boolean visible) { for(int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(visible); } }
Note: there is only one menu item with a submenu. In this submenu, all items are visible, but when I click on the item that is to appear in the ActionBar the other items, they simply do not appear more than one time. This only occurs in version 2.3 of Android. In the upper works well.
解决方案The
supportInvalidateOptionsMenu
is only valid forandroid 2.3 and lower
that is why it has a prefixsupport
on it, more likely if you use that theonPrepareOptionsMenu
is not called when you are trying to run it inandroid 2.3 and above
.solution:
You can check first if the device is
2.3 and lower
orabove
, if it is above you useinvalidateOptionsMenu()
for updating/calling theonPrepareOptionsMenu
这篇关于调用supportInvalidateOptionsMenu()后,菜单ActionBarActivity无法正常工作;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!