Say you have an attribute

<?xml version="1.0" encoding="utf-8"?>  
    <attr name="themedTextColor" format="reference" />

That gets set in your themes

<style name="MyLightTheme" parent="MyTheme">  
    <item name="themedTextColor">@color/text_color_light</item>

<style name="MyDarkTheme" parent="MyTheme">  
    <item name="themedTextColor">@color/text_color_dark</item>

<style name="MySepiaTheme" parent="MyTheme">  
    <item name="themedTextColor">@color/text_color_sepia</item>

<style name="MyBlueTheme" parent="MyTheme">  
    <item name="themedTextColor">@color/text_color_blue</item>
How would you get its color value at runtime?

Maybe you want to set a TextPaint with the color value, or maybe something else?

You might search and find code like this

TypedValue value = new TypedValue();

//true resolves the resource color value, 
//false would return you the value of that color
context.getTheme().resolveAttribute(R.attr.themedTextColor, value, true);

int color =;

TextPaint textPaint = new TextPaint(color);  

The problem I find is that color has a strange value in the debugger

And when I set the TextPaint with it, the text is drawn by the StaticLayout like this:

This color in my colors.xml has the hex value of #ff353535.

What does #ff353535 have to do with -13290187?

Well, -13290187 is just the integer representation of the argb (alpha red green blue) #ff353535.

Using the you can get the various color components out of the bits.


In the end, my problem was that I was calling new TextPaint(color) with a color, when that constructor takes an integer to represent flags

public class TextPaint extends Paint {  
    public TextPaint(int flags) {

Not very smart, but thankfully there is documentation and AOSP code to help. Replacing my code with

TextPaint textPaint = new TextPaint();  

Gives me the desired result.

Thanks for reading. I hope this helps someone.