先来看一个自定义属性重复的例子:
attrs.xml
<resources>
<declare-styleable name="View1">
<attr name="title_color" format="color" />
</declare-styleable>
<declare-styleable name="View2">
<attr name="title_color" format="color" />
</declare-styleable>
</resources>
这样会报错如下:
Found item Attr/color_type more than one time
解决办法也很简单,把相同的属性抽出来定义就可以。
<resources>
<attr name="title_color" format="color" />
<declare-styleable name="View1">
<attr name="title_color" />
</declare-styleable>
<declare-styleable name="View2">
<attr name="title_color" />
</declare-styleable>
</resources>
网友评论