android - DatePicker 标题文本颜色 : cannot resolve attribute

标签 android datepicker android-resources android-styles android-attributes

我想对 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

enter image description here

但我可以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在错误跟踪器上。

最佳答案

style attribute "android:attr/headerTextColor" is private

AAPT 表示该属性是私有(private)的。可能他们在 attrs.xml

中缺少一个 @hide

关于android - DatePicker 标题文本颜色 : cannot resolve attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44088795/

相关文章:

Android 资源选择布局和值不一致

android - 如何在我的 Android APK 中包含来自 JAR 的 Java 资源?

java - ResourcesCompat.getDrawable() 与 AppCompatResources.getDrawable()

java - 有没有办法在 Android 中使用没有按钮的 Twitter Digits?

android - 为什么不推荐使用 InsertHelper?

android - 如何使用 eclipse 在 apk 中包含预构建的共享库

php - 将日期选择器日期转换为 mysql 日期

android - ExpandableListView 组行中的 ImageButton 导致不触发 onClickListener

user-interface - Java datePicker - 如何在 JTextfield 中设置默认日期

c# - 返回错误答案的日期差异