如何使用自定义 textView 样式颜色覆盖 AppTheme textColor?

How to override AppTheme textColor with custom textView style color?

在 styles.xml appTheme 中指定了默认文本颜色 属性:

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

如果可以使用 styles.xml 文件中的这个新项目在某些需要的情况下覆盖它,那将是完美的:

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

并在所需的文本视图 xml 布局上指定它,如下所示:

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

问题是有些东西不起作用,因为自定义 textview 正在显示我的自定义主题的默认颜色(白色),而不是我为该 textview 的自定义样式指定的自定义颜色(绿色)。

我做错了什么?

如果您指的是资源类型(在本例中为 样式 ),则需要使用 at 符号 (@)。

更改以下内容:

style="style/CustomTextView"

为此:

style="@style/CustomTextView"