TextColor vs TextColorPrimary vs TextColorSecondary

rafvasq picture rafvasq · Aug 22, 2016 · Viewed 18.3k times · Source

What do each of these encompass in terms of text throughout an app?

More specifically, what would changing each of these in a theme change throughout my app? I'd like my buttons' texts to be a different color than my textviews; is one primary and the other secondary?

Any info related to these terms is appreciated!

Answer

Ryan Pierce picture Ryan Pierce · Aug 22, 2016

TextColor is just the xml attribute to set a color to the text of any given view.

TextColorPrimary is the default text color for enabled buttons and Large Textviews.

TextColorSecondary is the default text color for Medium and Small Textviews.

Ignore this, as for what you want to do, there is a better way. You want to edit your style.xml such that the default theme AppTheme (or whatever else you have declared as your theme in your manifest) contains the necessary xml attributes to customize your text colors.

The resulting AppTheme style will look like this when youre done.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColor">#hexColorForTextViews</item>
    <item name="android:buttonStyle">@style/myDefaultButton</item>
</style>

textColor will set the default color for all of your textviews. buttonStyle will reference a custom style that you want for all of your buttons. To make this work, add this style tag to your styles.xml file.

<style name="myDefaultButton">
    <item name="android:textColor">#hexColorForButtons</item>
    <!-- other stuff you want your buttons to inherit by default -->
</style>