私は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>
エラーが原因属性「タイトル」、すでにを定義されているの。 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);
どうすればこの問題を解決できますか?
類似しているhttp://stackoverflow.com/questions/4434327/same-named-attributes-in-attrs-xml-for-custom-view – Suragch