最近在写一个Android的library module,打算在库项目里面写一个自定义控件。
自定义控件里面有自己特有的属性。在attr.xml里面生成自己的自定义属性。
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="top_icon" format="reference" />
<attr name="bottom_icon" format="reference" />
<declare-styleable name="GradientIconView">
<attr name="top_icon" />
<attr name="bottom_icon" />
</declare-styleable>
<attr name="text" format="string" />
<attr name="text_size" format="dimension" />
<attr name="top_text_color" format="color" />
<attr name="bottom_text_color" format="color" />
<declare-styleable name

在创建Android library module并编写自定义控件时,遇到R文件报错问题。通过清理和重建项目未解决问题。实际上,错误出现在使用switch case语句处理R.styleable时,因为API14以后的库项目中Resource IDs不能在switch case中使用。解决方案是将switch case替换为if else。了解如何定位并解决R.java文件在特定场景下出现的错误是关键。
最低0.47元/天 解锁文章
510

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



