Search code examples
androidandroid-layouttextviewandroid-themeandroid-styles

How to override AppTheme textColor with custom textView style color?


Having default textColor property specified in styles.xml appTheme:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:textColor">@color/colorFontWhite</item>
    </style>

It whould be perfect if it is possible to override it for some desired cases using this new item on styles.xml file:

<style name="CustomTextView" parent="@android:style/Widget.TextView">
        <item name="android:textColor">@color/colorFontGreen</item>
    </style>

And specifying it on the desired textview xml layout like this:

<TextView
        android:id="@+id/text"       
        style="style/CustomTextView"/>

The problem is that something does not work, because the custom textview is being displayed with the default color of my custom theme (white) instead of the custom color specified on my custom style for that textview (green).

What am I doing wrong?


Solution

  • If you're referring to a resource type (a style in this case), you need to use the at-symbol (@).

    Change the following:

    style="style/CustomTextView"
    

    To this:

    style="@style/CustomTextView"