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?
Simply rename your file name by removing the numbers and only keep lower case letters or underscores.
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 ... !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With