[英]Custom Attributes in Android
我正在尝试为所有可编辑元素创建一个名为Tag的自定义属性。 我将以下内容添加到attrs.xml中
<declare-styleable name="Spinner">
<attr name="tag" format="string" />
</declare-styleable>
<declare-styleable name="EditText">
<attr name="tag" format="string" />
</declare-styleable>
我收到一条错误,说“EditText已经定义了属性标记”。 是否无法在不同的元素上创建同名的自定义属性?
如果要在多个位置使用attr,则将其放在<resources>
元素内的根元素中,如下所示:
<resources>
<attr name="tag" format="string" />
<declare-styleable name="Spinner">
<attr name="tag" />
</declare-styleable>
<declare-styleable name="EditText">
<attr name="tag" />
</declare-styleable>
</resources>
现在,您可以在此xml文件中的任何位置使用tag属性。
希望有所帮助。
看看我关于自定义属性的详细答案是否有帮助: 定义自定义attrs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.