ActionBarSherlock ForceOverflow资源未找到 [英] ActionBarSherlock ForceOverflow resource not found

查看:115
本文介绍了ActionBarSherlock ForceOverflow资源未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我升级到4.2版本,发现我的老code,因为它出现在ForceOverflow父主题已被删除未编译。

I upgraded to version 4.2 and found that my old code did not compile because it appears the ForceOverflow parent theme has been removed.

谷歌搜索这个问题看来,这是刻意去除,以保持后设备保持一致菜单按钮。

After Googling this issue it appears that the it was deliberately removed to maintain device consistent menu buttons.

我明白了使用物理菜单按钮的说法,但我不同​​意它......再加上它是如此该死的丑陋的旧菜单。

I do understand the argument for using the physical menu button, but I just don't agree with it... plus it is so damn ugly those old menus.

我真的不希望用户说他们不能访问previous功能(这毕竟是菜单按钮被转移是显示在屏幕上的原因),那么,什么是我选择这里?将在以后的版本中这个改变?我一定要坚持使用ABS的previous版本和处理,其中被固定在新版本的老ABS库的一些其他错误?有没有变通?

I really don't want users saying they cannot access previous functionality (which after all is the reason the menus buttons were moved to be visible on screen), so what are my options here? Will this be changed in a future release? Do I have to stick with a previous version of ABS and deal with some other bugs in the old ABS libs which were fixed in recent versions? Is there any work around?

推荐答案

而不是试图得到一个真正的溢出菜单中,我们可以伪造它的子菜单。

Instead of trying to get a "real" overflow menu, we can fake it with a SubMenu.

它看起来像和行为像原来的溢出按钮,就更好,因为它会永远存在。

It will look like and behave like the original overflow button, just better because it will always be there.

private Menu mainMenu;
private SubMenu subMenu1;

    @Override
public boolean onCreateOptionsMenu(Menu menu) {

    mainMenu = menu;

    subMenu1 = menu.addSubMenu("");
    subMenu1.add("Settings");
    subMenu1.add("About");
    subMenu1.add("Help");

    MenuItem subMenu1Item = subMenu1.getItem();
    subMenu1Item.setIcon(R.drawable.ic_menu_moreoverflow_normal_holo_dark);
    subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    return super.onCreateOptionsMenu(menu);
}

当然,你可以设置,就像你以前那样的子菜单。随着groudID,ITEMID等。

Of course you can set the subMenus just as you did before. With groudID, itemID etc.

请注意,我已经选用* ic_menu_moreoverflow_normal_holo_dark *作为菜单图标。 通过这种方式,按钮也可以看起来像溢出。

Note that I already choosed *ic_menu_moreoverflow_normal_holo_dark* as the menu icon. This way the button will also look like an overflow.

现在我们只需要这个子菜单打开时,用户pressed硬件菜单按钮。 如果设置主菜单,subMenu1再像以前那样,我们能够做到这一点很容易的。

Now we just need this Submenu to open when the user pressed the hardware menu button. We can do this very easy if you set mainMenu and subMenu1 like i did before.

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
            mainMenu.performIdentifierAction(subMenu1.getItem().getItemId(), 0);
            return true;
    }
    return super.onKeyUp(keyCode, event);
}

要注意的是导入:

Beware that you import:

import com.actionbarsherlock.view.SubMenu;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

不是

import android.view.MenuItem;

这篇关于ActionBarSherlock ForceOverflow资源未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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