学无先后,达者为师

网站首页 编程语言 正文

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

作者:teletian 更新时间: 2022-07-13 编程语言

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

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>

原文链接:https://blog.csdn.net/tianjf0514/article/details/125750217

栏目分类
最近更新