Andorid 自定义 View - 自定义属性 - 属性重复导致冲突

先来看一个自定义属性重复的例子:

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>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容