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

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, color starts in c #

The code is exactly as you see it.

+5
source share
2 answers

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

It amazes me that this error is still not fixed in Android Studio, searching on SO. It seems that she is mired in other people in different ways.

+11
source

Do one thing, and do not add color through color.xml, and then directly add activity color to Activity_main.xml in Activity_main.xml with your color hash code directly. For example, in your case android:background="#0000FF"

0
source

Source: https://habr.com/ru/post/1205732/


All Articles