【问题标题】:How to override AppTheme textColor with custom textView style color?如何使用自定义 textView 样式颜色覆盖 AppTheme textColor?
【发布时间】:2016-08-12 07:42:09
【问题描述】:

在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"/>

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

我做错了什么?

【问题讨论】:

  • style="style/CustomTextView" -> style="@style/CustomTextView"

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


【解决方案1】:

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

更改以下内容:

style="style/CustomTextView"

到这里:

style="@style/CustomTextView"

【讨论】:

  • 非常感谢!如果谷歌广告编译时间错误或带有此类错误的 lint 标记会更好:)
猜你喜欢
  • 1970-01-01
  • 2021-12-11
  • 2019-10-31
  • 2019-05-02
  • 2020-03-05
  • 1970-01-01
  • 2023-03-18
  • 2013-05-06
  • 1970-01-01
相关资源
最近更新 更多