【发布时间】:2013-09-16 12:19:35
【问题描述】:
我希望我的 ViewA 和 ViewB 都有“标题”标签。但我不能把这个放在attrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ViewA">
<attr name="title" format="string" />
</declare-styleable>
<declare-styleable name="ViewB">
<attr name="title" format="string" />
<attr name="max" format="integer" />
</declare-styleable>
</resources>
由于错误属性“title”已被定义。 Another question 显示了这个解决方案:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="title" format="string" />
<declare-styleable name="ViewB">
<attr name="max" format="integer" />
</declare-styleable>
</resources>
但在这种情况下,不会生成 R.styleable.ViewA_title 和 R.styleable.ViewB_title。我需要它们来使用以下代码从 AttributeSet 中读取属性:
TypedArray a=getContext().obtainStyledAttributes( as, R.styleable.ViewA);
String title = a.getString(R.styleable.ViewA_title);
我该如何解决这个问题?
【问题讨论】:
标签: java android xml declare-styleable styleable