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

标签 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"/>

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

我做错了什么?

最佳答案

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

更改以下内容:

style="style/CustomTextView"

对此:

style="@style/CustomTextView"

关于android - 如何使用自定义 textView 样式颜色覆盖 AppTheme textColor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38912545/

相关文章:

android - Apache Cordova 和 ADT - 更新 'www' 文件夹

android - 如何在 Android UI 中绘制圆角矩形?

android - 不支持的操作异常 : Can't convert to dimension: type=0x1

android - ExpandableListView.addHeaderView() 没有保留布局参数

android - 当没有足够的空间时,如何使图像调整大小而不是文本消失?

android - 增加 TextView 的 TextSize 然后减小它不会返回到 View 元素的正常高度

android - TextView 不会破坏文本

android - 如何减小应用程序的大小?

android - 设置具有多个目标的 Urban Airship - 可能有相同的 bundle ID?

updates - Android开发大app资源