问题描述
我的account_particle.xml布局中有这一行
I have this line in my account_particle.xml layout
android:padding="?attrs/disc_padding"
此attrs.xml:
this 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:
and this 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>
为什么会出现此编译错误?
Why do i get this compilation error?
error: Error: No resource found that matches the given name (at 'padding' with value '?attrs/disc_padding').
AccountParticle
AccountParticle
推荐答案
在布局属性中引用主题属性值的正确语法为:
The correct syntax for referring to a theme attribute value in a layout attribute is:
prefix:attribute="?attr/themeAttribute"
即attr
而不是attrs
.
尽管您可能已经在名为attrs.xml
的文件中定义了该属性,但文件名实际上是无关紧要的.构建资源时,将处理res/values*/
文件夹下的每个文件,无论文件名如何.
Though you may have defined that attribute in a file named attrs.xml
, the filename is actually irrelevant. When resources are being built, every file under the res/values*/
folder is processed, regardless of the filename.
这实际上意味着您可以在任意位置命名您的文件,并且可以将任何资源放置在所需的任何文件中.它们都将根据其类型进行处理,例如<attr>
,<color>
,<string>
等.
This effectively means that you can name your files there whatever you want, and you can put any resources there in whichever file you want. They will all be processed according to their type, like <attr>
, <color>
, <string>
, etc.
这篇关于错误:错误:找不到与给定名称匹配的资源(用于属性引用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!