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>
エラーのためAttribute "title" has already been defined . 別の質問は、この解決策を示しています。
<?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
andR.styleable.ViewB_title
は生成されません。次のコードを使用して AttributeSet から属性を読み取るために必要です。
TypedArray a=getContext().obtainStyledAttributes( as, R.styleable.ViewA);
String title = a.getString(R.styleable.ViewA_title);
どうすればこれを解決できますか?