调用supportInvalidateOptionsMenu()后,菜单ActionBarActivity无法正常工作; [英] Menu ActionBarActivity not work after calling supportInvalidateOptionsMenu();

查看:1454
本文介绍了调用supportInvalidateOptionsMenu()后,菜单ActionBarActivity无法正常工作;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与图书馆和抽屉菜单的兼容性工作。

调用supportInvalidateOptionsMenu()函数后;在弹出菜单中没有出现,只留下核心流图标。

这个解决的办法?

为此在我ActMain(非常碎片主要活动)

  @覆盖
    prepareOptionsMenu(菜单菜单)上公共布尔{        //如果资产净值抽屉被打开,隐藏操作项相关内容视图
        布尔drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
        hideMenuItems(菜单,drawerOpen!);
        返回super.on prepareOptionsMenu(菜单);
    }    私人无效hideMenuItems(菜单菜单,布尔可见)
    {        的for(int i = 0; I< menu.size();我++){            menu.getItem(ⅰ).setVisible(可见);
        }
    }


  

请注意:只有一个有子菜单项。在这个子菜单中,所有
  项目是可见的,但是当我点击即出现在项目
  在ActionBar其他项目,他们根本不会出现一个以上的
  时间。这仅发生在的Andr​​oid 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 for android 2.3 and lower that is why it has a prefix support on it, more likely if you use that the onPrepareOptionsMenu is not called when you are trying to run it in android 2.3 and above.

solution:

You can check first if the device is 2.3 and lower or above, if it is above you use invalidateOptionsMenu() for updating/calling the onPrepareOptionsMenu

这篇关于调用supportInvalidateOptionsMenu()后,菜单ActionBarActivity无法正常工作;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆