You should use:
For a sanity check, I just tried it, because I had a project open anyway, and yes, it's nice and red ;D
You can use various functions from the Color class to get the same effect of course.
And of course, if you want to define your color in an XML file, you can do this:
because the getColor() function is deprecated1, you need to use it like so:
You can also insert plain HEX, like so:
Where you have an alpha-channel first, then the color value.
Check out the complete manual of course, public class Color extends Object.
1This code used to be in here as well:
This method is now deprecated in Android M. You can however use it from the contextCompat in the support library, as the example now shows.
In addition, if the text is a link you need to use text.setLinkTextColor(...); in code or android:textColorLink="..." in XML
@Nanne It would be nice if your answer also mentioned that R.color.XXX is a reference to the color. Meaning that it needs to be dereferenced (as it is in your example), for clarity.
I'm not sure what you mean? As in, dereferenced and so will use more resources or do you mean something else?
Is there any way of telling if a particular color value is going to let a text disappear?