是否有可能变为灰色(不只是禁用)一个菜单项中的Andr​​oid? [英] Is it possible to grey out (not just disable) a MenuItem in Android?

查看:246
本文介绍了是否有可能变为灰色(不只是禁用)一个菜单项中的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关于黑莓相同的功能一个问题,提到这错误几个不同的线程(这已被关闭,而不会分辨率据我可以告诉),但我还没有找到一个专门为Android。

There's a question for the same functionality on Blackberry, and a few different threads referred to this bug (which has since been closed without resolution as far as I can tell), but I haven't found one specifically for Android.

我打电话的setEnabled(假)基于一些国家一定的MenuItems,但它们在视觉上看起来是一样的。我希望他们能够以某种方式被抵消,从而使用户知道该选择当前不可用 - ?有没有办法做到这一点。

I'm calling setEnabled(false) on certain MenuItems based on some state, but they visually look the same. I'd like them to be offset in some way, so that the user knows that the option currently isn't available -- is there any way to do that?

推荐答案

我有同样的问题。有得到这个工作的方式有两种:

I had the same issue. There are two ways of getting this to work:

  1. 把你的图标在StateList,使得不同的图标将在禁用
  2. 使用
  3. 我现在用的是什么。

  1. Put your icons in a StateList so that a different icon will be used on disable
  2. What I use now. Change the icon yourself with something like this in onPrepareOptionsMenu():

public boolean onPrepareOptionsMenu(Menu menu) {
    boolean menusEnabled = reachedEndOfSlidehow(); // enable or disable?
    MenuItem item = menu.findItem(R.id.menu_next_slide);
    Drawable resIcon = getResources().getDrawable(R.drawable.ic_next_slide);

    if (!menusEnabled)
        resIcon.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);

    item.setEnabled(menusEnabled); // any text will be automatically disabled
    item.setIcon(resIcon);
}

您可以致电 invalidateOptionsMenu()(或ABS, supportInvalidateOptionsMenu())重建菜单。

You can call invalidateOptionsMenu() (or from ABS, supportInvalidateOptionsMenu()) to rebuild the menu.

修改:更新的解决方案2

EDIT: Updated solution 2

来源:<一href="https://groups.google.com/forum/?fromgroups#!topic/actionbarsherlock/Z8Ic8djq-3o">https://groups.google.com/forum/?fromgroups#!topic/actionbarsherlock/Z8Ic8djq-3o

这篇关于是否有可能变为灰色(不只是禁用)一个菜单项中的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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