Take the 2-minute tour ×

I have a custom component that I want to give the same colors as a TextView. That is, I don't want to copy its colors, I want to get the default background and foreground colors, if there's such a concept on android.


The following seems to yield the text color of my TextView. But is it just luck? It's not intuitive to me that a default TextView would use android.R.attr.textColorSecondary? And why does not resolveAttribute return the color directly?

TypedValue tv = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.textColorSecondary, tv, true);
Color holyColor = getResources().getColor(tv.resourceId);


I found the source code of TextView at android.git.kernel.org, but it seemed to contain a lot of referrences to com.android.internal.R, which I don't think I should use in my own code. I'm currently looking for some kind of evidence that TextView uses android.R.attr.textColorSecondary.


I found some kind of evidence at developer.android.com, in styles.xml that TextView uses android.R.attr.textAppearanceSmall. textAppearanceSmall is documented to default to "secondary text color".

I guess I was lucky after all, but I still don't like that little code snippet of mine.

share|improve this question
Your observation is also backed by the documentation here: http://developer.android.com/guide/topics/resources/accessing-resources.html#Re‌​ferencesToThemeAttributes –  fr1550n May 25 '12 at 9:52
add comment

1 Answer

up vote 0 down vote accepted

What you're looking for are attributes. Attributes link widgets to styles. For example, android:background is what you'd set for a particular view, but there's attributes like android:panelBackground and android:windowBackground that you can use override to affect the system as a whole.

You should look through R.attr and then link to those attributes in your widget. There should be a number of them that are linked to TextView; it would make sense to download the Android source code and see which attributes are used.

share|improve this answer
add comment

Your Answer


