更改默认文本颜色,并仍呈现不同的颜色已禁用菜单项 [英] Changing default text colour and still showing disabled menu items in different colour

查看:184
本文介绍了更改默认文本颜色,并仍呈现不同的颜色已禁用菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Theme.Holo.Light 为基本主题,设计师注意到,默认的文本颜色不黑,但暗灰色的( #505050 )。我们希望将它更改为黑色。

With Theme.Holo.Light as the base theme, a designer noticed that the default text colour is not black, but a dark grey (#505050). We'd like to change it to black.

寻找一个简单的方法来更改默认为黑色无处不在的应用程序,我发现这工作:

Looking for a simple way to change the default to black everywhere in the app, I found that this works:

<resources>    
    <style name="MyAppTheme" parent="android:Theme.Holo.Light">
        <item name="android:textColor">@android:color/black</item>
    </style>
</resources>

现在,问题,这也改变了在操作栏的溢出菜单中的禁用项目的颜色。 如何覆盖默认的文本颜色同时还具有禁用菜单项看禁用?

Now, problem is, that also changes the colour of disabled items in Action Bar's overflow menu. How to override default text colour while still having disabled menu items look "disabled"?

菜单看起来应该像下面,但使用​​机器人:文字颜色如上所述,它改变了所有的项目都黑

The menu should look something like below, but using android:textColor as above, it changes all the items to black.

我尝试用 textColorPrimaryInverse textColorPrimaryDisableOnly textColorPrimaryInverseDisableOnly disabledAlpha 但这些似乎并没有影响到溢出菜单。

I was experimenting with textColorPrimaryInverse, textColorPrimaryDisableOnly, textColorPrimaryInverseDisableOnly and disabledAlpha but those didn't seem to affect the overflow menu.

推荐答案

您可以使用一个绘制的文本颜色,并绘制您可以使用选择根据允许状态来选择颜色。使用下面绘制定义的颜色会让你禁用菜单项灰色,其余的黑色。

You can use a drawable as the text colour, and in drawable you can use selector to select the colour according to enabled status. Using following drawable definition as colour will make your disabled menu items grey and the rest black.

在如 RES /绘制/ default_text_colour.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@android:color/darker_gray"/>
    <item android:color="@android:color/black"/>
</selector>

然后,使用绘制:

Then, using the drawable:

<item name="android:textColor">@drawable/default_text_colour</item>

这篇关于更改默认文本颜色,并仍呈现不同的颜色已禁用菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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