设置可绘制文本颜色抛出一个异常“颜色值必须以#” [英] Setting Drawable as text color raise an exception 'Color value must start with #'
问题描述
在布局
我用按钮
我设置其文字颜色
来一个绘制如下:
In a layout
I use a button
which I set its textColor
to a drawable as follows :
@ drawble / text_color_drawable:
@drawble/text_color_drawable :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- disabled state -->
<item android:state_enabled="false" android:color="@color/disabled_text_color" />
<item android:color="@color/main_text_color"/>
</selector>
@色/ main_text_color:
@color/main_text_color :
<color name="main_text_color">#9797A3</color>
但是,当我使用这个绘制
名为 text_color_drawable
为文字颜色
:机器人:文字颜色=@绘制/ text_color_drawable
结果
我得到一个异常:渲染过程中提出的例外:颜色值text_color_drawable必须以#启动
我是不是做错了什么?
感谢您
推荐答案
该问题可能是 @ drawble / text_color_drawable
:它不应该是一个绘制,但而是一个结果
'颜色'。基本上,你目前所拥有的是一个 StateListDrawable
,但你真正想要的是一个 ColorStateList
。两者都是非常相似的,但住在资源不同的地方。
The problem may be@drawble/text_color_drawable
: it shouldn't be a 'drawable', but rather a
'color'. Basically what you currently have is a StateListDrawable
, but what you really want is a ColorStateList
. Both are quite similar, but live in different places in the resources.
话虽这么说,试着将文件从 RES /绘制
移动到 RES /颜色
。当你再分配资源作为文本颜色,应该说:机器人:文字颜色=@色/ text_color_drawable
That being said, try moving the file from res/drawable
to res/color
. When you then assign the resource as text color, it should say: android:textColor="@color/text_color_drawable"
这篇关于设置可绘制文本颜色抛出一个异常“颜色值必须以#”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!