Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to convert @color/Blue into a drawable when setting background color

Tags:

android

res/layout/activity_main.xml

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@color/Blue">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     />
</RelativeLayout>

meanwhile, res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="Blue">#0000FF</color>
</resources>

as you can see, the color does start with #

The code is exactly as you see it.

like image 883
HukeLau_DABA Avatar asked Oct 28 '14 21:10

HukeLau_DABA


People also ask

How do I change the color of a drawable in XML?

Use app:drawableTint="@color/yourColor" in the xml instade android:drawableTint="@color/yourColor" .


1 Answers

I have to go to File-->Invalidate Cache/Restart.

It amazes me that this bug still hasn't been fixed in Android Studio, searching on SO it looks like it has plagued other people in different ways.

like image 54
HukeLau_DABA Avatar answered Nov 04 '22 00:11

HukeLau_DABA