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
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.
Android applications use XML to create layout files. Unlike HTML, XML is case-sensitive, requires each tag be closed, and preserves whitespace.
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.
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.
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.
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