我希望我的 ViewA 和 ViewB 都有 "title" 标签,但我不能把它放在 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"已经被定义。 另一个问题提供了以下解决方案:
<?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);
我该如何解决这个问题?