自定义属性的时候报错:
<?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 definedError: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时遇到属性'color'已定义的错误,由于AppCompat库中默认包含该属性,导致编译失败。解决办法是将自定义属性更改为不冲突的名称。
31万+

被折叠的 条评论
为什么被折叠?



