Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android .xml files: Why do predefined colors not work for me?

Tags:

android

When I look at misc. Android tutorials and examples when it comes to specifying colors I very often see constants like @color/red or @color/black etc. being used. For some strange reason that NEVER works for me! I always need to specify colors using the "#RGB", #ARGB, ..., #AARRGGBB notation.

As soon, as I try to use any of those mnemonic constants like e.g. "@color/red" I am getting error messages like these:

[...] C:\Users\mmo\Test\res\drawable\edit_text.xml:5: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/orange'). [...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:3: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/black'). [...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:4: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/black'). [...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:5: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/green'). [...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:6: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/black'). 

Why is that so? Why can't I use these predefined constants? Do I need to prefix them with some package name (I tried @android:color/red but that only caused a different error)? Do I need to specify these colors myself? If so: how and where? Any ideas or suggestions?

Michael

like image 273
mmo Avatar asked Oct 18 '10 22:10

mmo


People also ask

How do you change the color of an XML file?

Android TextView – Text Color. TextView Text Color – To change the color of text in TextView, you can set the color in layout XML file using textColor attribute or change the color dynamically in Kotlin file using setTextColor() method.

Does Android still use XML?

Android applications use XML to create layout files. Unlike HTML, XML is case-sensitive, requires each tag be closed, and preserves whitespace.

What is colors XML?

colors. xml is an XML file which is used to store the colors for the resources. An Android project contains 3 essential colours namely: colorPrimary. colorPrimaryDark.

Where is colors XML in Android Studio?

Android Resources Define colors xml in the /res/values/ folder. Colors are represented by hexadecimal color values for each color channel (0 - FF) in one of the formats: #RGB. #ARGB.


1 Answers

If you want to use the colors pre-defined in the Android platform, the syntax is @android:color/white. The "android:" at the beginning indicates that the resource is not part of your application.

like image 55
Romain Guy Avatar answered Oct 14 '22 07:10

Romain Guy