我想对DatePicker
应用某种样式。在platform's attrs.xml
中,我们可以看到attrs.xml
可设置样式的以下属性:
DatePicker
虽然我可以引用<declare-styleable name="DatePicker">
...
<!-- The text color for the selected date header text, ex. "2014" or
"Tue, Mar 18". This should be a color state list where the
activated state will be used when the year picker or day picker is
active.-->
<attr name="headerTextColor" format="color" />
<!-- The background for the selected date header. -->
<attr name="headerBackground" />
...
</declare-styleable>
,但我无法为android:headerBackground
属性执行此操作。因此,下面的代码在android:headerTextColor
:
styles.xml
提示错误,<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.DatePicker">
<item name="android:headerBackground">@color/red</item>
<item name="android:headerTextColor">@color/red</item>
</style>
无法解析。
android:headerTextColor
但是我可以 clearly see覆盖该属性。有趣的是,该代码块前面带有Widget.Material.DatePicker
注释,这可能以某种方式导致此行为的原因。
此行为可能是什么原因以及如何覆盖该属性?
在Android Studio 2.3上运行,minSdkVersion 23,buildToolsVersion 25.0.3,compileSdkVersion和targetSdkVersion 23,无效的缓存和清理的项目。
您可以在Attributes for new-style DatePicker
中看到,某些属性后面有此文本:
此常量在API级别23中已弃用。改为使用headerTextColor。
这意味着该属性应该公开给公共API,但是由于某种原因,它已被剥离,AAPT无法访问它。
在错误跟踪器处打开R.attr
docs。
R.attr
已经有一段时间了,但是由于尚未解决,我通过在这样的片段中调用picker.show()之后,获取标题的视图ID,然后直接以编程方式设置文本颜色来解决此问题。希望这会帮助在这个问题上迷路的人。
尝试使用此