Say you have an attribute

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

That gets set in your themes

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

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

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

<style name="MyBlueTheme" parent="MyTheme">  
    <item name="themedTextColor">@color/text_color_blue</item>
</style>  
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 R.id value of that color
context.getTheme().resolveAttribute(R.attr.themedTextColor, value, true);

int color = value.data;

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 android.graphics.Color you can get the various color components out of the bits.

Color.argb(  
    Color.alpha(color), 
    Color.red(color), 
    Color.green(color), 
    Color.blue(color))

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) {
        super(flags);
    }
    ...
}

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

TextPaint textPaint = new TextPaint();  
textPaint.setColor(color);  

Gives me the desired result.

Thanks for reading. I hope this helps someone.