gpt4 book ai didi

android - 自定义属性错误 - Android Studio 1.2

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:43:49 25 4
gpt4 key购买 nike

在我的 Android 项目中,我有几个使用自定义属性的自定义组件。

attrs.xml 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources >
<declare-styleable name = "TextBox">
<attr name = "font" format = "string"/>
</declare-styleable>

<declare-styleable name = "ButtonBox">
<attr name = "font" format = "string"/>
</declare-styleable>
</resources>

我在自定义组件中很好地引入了属性,但是当我运行代码时,我看到了以下错误。

Error: Found item Attr/font more than one time
Error: Execution failed for task ':app:mergeDebugResources'.

在两个不同的 declare-styleable 资源中有相似的属性名称应该没有区别吧?

如有帮助,将不胜感激,谢谢!

最佳答案

如你所见here , attr 本身可以有多个属性,并且只能定义一次,你可以在里面配置多个细节。所以你应该给它不同的名字,或者,因为它们有相同的属性,所以两者只使用一个 declare-styable

查看 this link也有一个很好的例子。

它应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<resources >
<declare-styleable name="Box">
<attr name="font" format="string"/>
</declare-styleable>
</resources>

您可以在文本、按钮等上使用 Box

关于android - 自定义属性错误 - Android Studio 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30038982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com