我想对 DatePicker
应用一些样式。在 platform's 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
覆盖该属性。有趣的是,该代码块前面有 Attributes for new-style DatePicker
注释,这可能以某种方式导致此行为的原因。
此行为的原因可能是什么以及如何覆盖该属性?
在 Android Studio 2.3、minSdkVersion 23、buildToolsVersion 25.0.3 上运行, compileSdkVersion & targetSdkVersion 23,无效缓存和清理项目。
正如您在 R.attr
docs 中看到的那样, 一些属性后面有这段文字:
This constant was deprecated in API level 23. Use headerTextColor instead.
这意味着,该属性应该公开给公共(public) API,但不知何故它被剥离并且 AAPT 无法访问它。
已打开 an issue在错误跟踪器上。
最佳答案
关于android - DatePicker 标题文本颜色 : cannot resolve attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44088795/