Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix android error 'Color value must start with #'?

Tags:

android

I was trying to use an icon from this page in my layout as follows

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_backspace_black_24dp"
/>

but it could not be rendered because of an error

Color value '@drawable/ic_backspace_black_24dp' must start with #

I found two related issues in SO here and here which did not help resolve the issue.

There is no dash ('-') in the filename, the file-format is a 'png' and there is no res/color directory in my project.

All my colors defined in colors.xml start with a #.

So how to fix this error?

like image 798
Alex Avatar asked Jan 12 '16 19:01

Alex


2 Answers

Simply rename your file name by removing the numbers and only keep lower case letters or underscores.

like image 151
romric Avatar answered Sep 20 '22 00:09

romric


Problem solved: I forgot to remember that the android sources on the internet are really outdated, and almost none of the documentation works as-is!

The folder res/drawable as suggested in the android developer guide is deprecated! The folder is now named mipmap! So the simple solution is to have the following layout to fix the problem:

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_backspace_black_24dp"
/>

Never trust the android developer documentation ... !

like image 43
Alex Avatar answered Sep 20 '22 00:09

Alex