自定义View里面的自定义属性的时候报错:Attribute "color" has already been defined

自定义属性的时候报错:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="NotePadView">

        <attr name="color" format="color"></attr>
        <attr name="lineHeight" format="dimension"></attr>
    </declare-styleable>
</resources>


C:\AndroidStudioProjects\CustomerView\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.1.1\res\values\values.xml

Error:(2) Attribute "color" has already been defined
Error:Execution failed for task ':app:processDebugResources'.

> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Android\sdk\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1


因为color 这个属性默认的就是 有的,所以一定不能使用这个属性:

解决方法:

修改属性为其他的名字:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="NotePadView">

        <attr name="lineColor" format="color"></attr>
        <attr name="lineHeight" format="dimension"></attr>
    </declare-styleable>
</resources>


你可能感兴趣的:(自定义View里面的自定义属性的时候报错:Attribute "color" has already been defined)