android - 错误:错误:未找到与给定名称匹配的资源(用于属性参考)
问题描述
我的 account_particle.xml 布局中有这一行
android:padding="?attrs/disc_padding"
这个 attrs.xml:
<resources>
<declare-styleable name="AccountParticle">
<attr name="apStyle" format="enum">
<enum name="header" value="0"/>
<enum name="list_item" value="1"/>
</attr>
<attr name="text_margin_start" format="reference"/>
<attr name="text_margin_end" format="reference"/>
<attr name="text_margin_right" format="reference"/>
<attr name="text_margin_left" format="reference"/>
<attr name="disc_padding" format="reference"/>
<attr name="disc_imageViewSize" format="reference"/>
</declare-styleable>
</resources>
这个styles.xml:
<style name="Theme.ap.header" parent="Theme.AppCompat">
<item name="disc_padding">@dimen/account_menu_header_signed_in_avatar_margin_start</item>
</style>
<style name="Theme.ap.list_item" parent="Theme.AppCompat">
<item name="disc_padding">@dimen/account_menu_account_list_item_avatar_margin_start</item>
</style>
为什么我会收到此编译错误?
error: Error: No resource found that matches the given name (at 'padding' with value '?attrs/disc_padding').
帐户粒子
解决方案
该问题与应该使用的属性用法有关,?attr/
而不是?attrs/
.
但是您的attrs.xml
文件中还有另一个问题。问题是您在 a 中声明了以下引用declare-styleable
:
<attr name="text_margin_start" format="reference"/>
<attr name="text_margin_end" format="reference"/>
<attr name="text_margin_right" format="reference"/>
<attr name="text_margin_left" format="reference"/>
<attr name="disc_padding" format="reference"/>
<attr name="disc_imageViewSize" format="reference"/>
此引用应移出declare-styleable
为什么
declare-styleable
用于定义attrs
将在自定义视图的上下文中使用的一组。在您的情况下,在disc_padding
a 的上下文之外使用AccountParticle
.
文档参考:https ://developer.android.com/training/custom-views/create-view#customattr
推荐阅读
- azure-devops - 通过 SSH 复制文件失败“错误:无法解析 privateKey:不支持的密钥格式。”
- regex - 将单元格数据转置为单独的行
- java - 通过网络发送 AVPacket
- javascript - 与 Angular (4.0.0) 和 Material 2.0.0-beta.8 的数据绑定
- javascript - 在 Node.js 网络应用程序上使用 Puppeteer 来进行网络抓取?
- python - 如何在 django 中将用户名作为另一个模型的外键
- google-chrome - Puppeteer 无法使用铬在无头模式下工作
- html - scss中带有正常文本的倾斜div
- javascript - jQuery DataTable 事件未触发
- leaflet - 这些缝隙叫什么?在哪里设置它们?