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

时间:2016-08-12 07:42:10

标签: android android-layout textview android-theme android-styles

在styles.xml appTheme:

中指定了默认的textColor属性
<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>

并在所需的textview xml布局上指定它,如下所示:

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

问题是某些东西不起作用,因为自定义文本视图使用我的自定义主题(白色)的默认颜色显示,而不是在我的自定义样式上为该文本视图指定的自定义颜色(绿色)。

我做错了什么?

由于

1 个答案:

答案 0 :(得分:3)

如果您指的是资源类型(在这种情况下为样式),则需要使用at符号(@)。

更改以下内容:

style="style/CustomTextView"

对此:

style="@style/CustomTextView"
相关问题