Error:error: resource previously defined here. AAPT2 error: check logs for details

如果你遇到了以下的问题:

这里写图片描述

说明你可能遇到跟我一样的问题了。

AAPT

AAPT是Android Asset Packaging Tool的缩写,即安卓文件打包工具。作用是将安卓资源文件编译成二进制文件。

问题产生

我在自定义View的时候,自定义了attr属性,添加了一个textColor的属性值,为的是接收文字颜色值。

<declare-styleable name="RollTextView">
        <attr name="textColor" format="color"/>
        <attr name="textSize" />
</declare-styleable>

结果运行的时候就出现了上述的问题,原因是因为重定义了系统的属性值。

解决办法

1、重命名textColor,名称不与系统的textColor一样即可。

<declare-styleable name="RollTextView">
        <attr name="text_color" format="color"/>
        <attr name="textSize" />
</declare-styleable>

2、不对textColor进行重命名,直接引用系统的textColor,然后在xml里面使用时,就不能使用自定义的命名空间了(例如:app:),得用使用原生的引用(android:),千里之堤,毁于蚁穴,稍加注意就好。

<declare-styleable name="RollTextView">
        <attr name="textColor" />
        <attr name="textSize" />
</declare-styleable>

特此做个小笔记。

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值