I want to create a custom class that takes a color as one of its attributes when laid out in an Android XML file. However, a color could be a resource or it could be one of a number of direct color specifications (eg a hex value). Is there a simple preferred method for using AttributeSet to retrieve the color, since an integer representing a color could refer either to a resource value or an ARGB value?
I want to create a custom class that takes a color as one of
Share
Let’s say you have defined your custom color attribute like this:
Then in the constructor of your view, you can retrieve the color like this:
You don’t actually have to worry how the color attribute was populated, either like this
or like this:
The
getColormethod will return a color value in any case.