同一个Library中,不同的自定义View需要用不同的declare-styleable,如果两个不同的declare-styleable存在相同的属性就会构建失败,下面就是解决该问题的方法.
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<declare-styleable name="StepperIndicator" tools:ignore="ResourceName">
<attr name="stpi_stepCount" format="integer"/>
</declare-styleable>
<declare-styleable name="StepperIndicator2" tools:ignore="ResourceName">
<attr name="stpi_stepCount" format="integer"/>
</declare-styleable>
</resources>
类似上面这样的写法就会导致构建失败,应该将相同的属性提取出来添加到resources
节点中,然后在declare-styleable
节点中引入该属性.
<resources xmlns:tools="http://schemas.android.com/tools">
<attr name="stpi_stepCount" format="integer"/>
<declare-styleable name="StepperIndicator" tools:ignore="ResourceName">
<attr name="stpi_stepCount"/>
</declare-styleable>
<declare-styleable name="StepperIndicator2" tools:ignore="ResourceName">
<attr name="stpi_stepCount"/>
</declare-styleable>
</resources>