我正在尝试将所有的样式放入我的应用主题中。然而,我在更改TextView的文本颜色时遇到了困难。以下是我attrs.xml文件中的内容。
<?xml version="1.0" encoding="utf-8"?>
<declare-styleable name="flat">
<attr name="detail_name_view" format="reference" />
</declare-styleable>
这来自于我的styles.xml文件
<style name="flat_theme" parent="android:Theme.NoTitleBar">
<item name="detail_name_view">@style/flat_detail_name</item>
</style>
<style name="flat_detail_name" parent="@android:style/Widget.TextView">
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:textColor">@color/detail_group_black</item>
<item name="android:textSize">16sp</item>
<item name="android:singleLine">true</item>
<item name="android:ellipsize">end</item>
</style>
这是来自我的 layout.xml 文件
<TextView
android:id="@+id/detail_name"
style="?detail_name_view"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:gravity="left|center_vertical" />
我已经正确设置了以下清单。
<application
android:name="com.example.blah"
android:icon="@drawable/blah"
android:label="@string/app_name"
android:theme="@style/flat_theme"
颜色从未更改为 "@color/detail_group_black"。我是不是漏掉了什么简单的东西?或者问题是Android已经为TextView创建了一个textColor属性,所以样式不能覆盖它?我的属性主题策略似乎对应用程序的其余部分效果很好,但对这个没有用。有什么想法吗?谢谢。
另外,如果可以不创建自定义TextView类来进行此更改,我会更好:这是一个相当大的项目,我不确定如果我扩展TextView会遇到什么问题。
编辑:另外,如果我将TextView更改为style="@style/flat_detail_name_view",它可以正常工作。我不想这样做的原因是,我可以通过更改主题来更改这些文本视图的外观。在所有其他视图上使用style="?something_else"可以起作用,所以我真的不明白这一点,可能是我漏掉了什么简单的东西?