无法从android命名空间解析属性

azi*_*ian 7 android datepicker android-resources android-styles android-attributes

我想应用一些风格DatePicker.在平台中,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>
Run Code Online (Sandbox Code Playgroud)

虽然我可以参考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>
Run Code Online (Sandbox Code Playgroud)

提示有错误,android:headerTextColor无法解决.

在此输入图像描述

但我可以清楚地看到 Widget.Material.DatePicker压倒那个属性.有趣的是,这段代码前面有Attributes for new-style DatePicker注释,这可能会以某种方式导致这种行为的原因.

可能是这种行为的原因以及如何覆盖该属性?

在Android Studio 2.3,minSdkVersion 23,buildToolsVersion 25.0.3,compileSdkVersion和targetSdkVersion 23上运行,无效的缓存和清理项目.


正如您在R.attr文档中看到的,这些文本背后有一些属性:

此常量在API级别23中已弃用.请改用headerTextColor.

这意味着,该属性应该暴露给公共API,但不知何故它被剥离,AAPT无法访问它.

在bug跟踪器上打开了一个问题.

Tin*_*ran 5

样式属性“android:attr/headerTextColor”是私有的

AAPT 表示该属性是私有的。可能他们缺少一个@hideinattrs.xml


Amj*_*han -1

尝试使用这个

样式.xml

 <style name="DatePicker">
        <item name="android:headerBackground">@color/colorPrimaryDark</item>
        <item name="headerTextColor">@color/colorAccent</item>
 </style>
Run Code Online (Sandbox Code Playgroud)

值文件夹 attr.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <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" />
    </declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)