微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我想将一些样式应用于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覆盖该属性.有趣的是,大量代码前面有新式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.

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

在bug跟踪器上打开an issue.

解决方法

style attribute android:attr/headerTextColor is private

AAPT说该属性是私有的.可能他们错过了attrs.xml中的@hide

原文地址:https://www.jb51.cc/android/315309.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐