在styles.xml中指定了默认的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"/>
问题是有些东西不起作用,因为自定义textview正在显示我的自定义主题的默认颜色(白色),而不是我的自定义样式指定的自定义颜色为该textview(绿色)。
我做错了什么?
如果您引用的是资源类型(在本例中为样式),则需要使用at符号(@
)。
修改如下:
style="style/CustomTextView"
:
style="@style/CustomTextView"