Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :

<?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>

@color/main_text_color :

<color name="main_text_color">#9797A3</color>

But when I use this drawable called text_color_drawable as textColor : android:textColor="@drawable/text_color_drawable"
I get an exception : Exception raised during rendering: Color value text_color_drawable must start with #

Am I doing something wrong ?

Thank you

like image 424
SagiLow Avatar asked Feb 23 '14 17:02

SagiLow


2 Answers

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.

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"

like image 148
MH. Avatar answered Nov 10 '22 08:11

MH.


In my case a refresh button has helped. It is placed in a small toolbar over a design view, near magnifiers (with icons like 1:1, +, -).

like image 37
CoolMind Avatar answered Nov 10 '22 08:11

CoolMind