Aru*_*run 30 android custom-attributes
我正在尝试为所有可编辑元素创建一个名为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>
Run Code Online (Sandbox Code Playgroud)
我收到一条错误,说"EditText已经定义了属性标记".是否无法在不同的元素上创建同名的自定义属性?
nin*_*nse 70
如果要在多个位置使用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>
Run Code Online (Sandbox Code Playgroud)
现在,您可以在此xml文件中的任何位置使用tag属性.
希望有所帮助.
| 归档时间: |
|
| 查看次数: |
12941 次 |
| 最近记录: |