在 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"/>
问题是有些东西不起作用,因为自定义 TextView 正在使用我的自定义主题的默认颜色(白色)显示,而不是在我的自定义样式中为该 TextView 指定的自定义颜色(绿色)。
我做错了什么?
最佳答案
如果您引用资源类型(在本例中为样式),则需要使用 at 符号 (@
)。
更改以下内容:
style="style/CustomTextView"
对此:
style="@style/CustomTextView"
关于android - 如何使用自定义 textView 样式颜色覆盖 AppTheme textColor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38912545/