禁止在Android的文本视图颜色没有变化 [英] Android text view color doesn't change when disabled

查看:148
本文介绍了禁止在Android的文本视图颜色没有变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打电话的setEnabled(假)的一个TextView对象中的文本颜色没有变化。我预计它会变成灰色。如果我删除线:在我的XML文件Android的文字颜色,它备份到正常

When I call setEnabled(false) for a TextView object the text color doesn't change. I expected it will be changed to gray. If I remove the line of "android:textColor" in my XML file, it backs to normal.

任何想法?

推荐答案

我觉得发生了什么事是,因为你覆盖默认的文本颜色它不继承其他文本颜色样式。尝试创建一个<一个href="http://developer.android.com/reference/android/content/res/ColorStateList.html">ColorStateList它和设置文字颜色属性它,而不是一种颜色。

I think what's happening is that since you're overriding the default textcolor it isn't inheriting the other textcolor styles. Try creating a ColorStateList for it and setting the textColor attribute to it instead of to a color.

在一个彩色文件(如RES /彩色/的example.xml):

In a color file (eg res/color/example.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="@color/disabled_color" />
    <item android:color="@color/normal_color"/>
</selector>

然后在您的布局:

then in your layout:

<TextView
    android:text="whatever text you want"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/example" />

请注意,我还没有在一段时间这样做,我是从内存中输入了很多本,所以它可能需要一些调整。该ColorStateList文档(上面链接)有更充实出例如对于颜色的XML文件。

Note, I haven't done this in a while and I'm typing a lot of this from memory, so it may need a little tweaking. The ColorStateList docs (linked above) have a more fleshed-out example for the color XML file.

这篇关于禁止在Android的文本视图颜色没有变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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