首页 > 解决方案 > 子模块自定义属性 AndroidStudio 有 lint 问题

问题描述

当我像这样声明我attrs的 at 子模块时:

<attr name="radius" format="dimension" />
<attr name="border" format="dimension" />
<attr name="border_color" format="reference|color" />

<declare-styleable name="RoundImageView">
    <attr name="radius" />
    <attr name="border" />
    <attr name="border_color" />
</declare-styleable>

<declare-styleable name="CircleImageView">
    <attr name="border" />
    <attr name="border_color" />
</declare-styleable>

但是当我在我的应用程序中使用时,attr 无法自动提示:

在此处输入图像描述

顺便说一句,这在我运行应用程序时效果很好。只是有 lint 通知和属性没有提示。

标签: androidandroid-layoutandroid-studio

解决方案


您的问题可能是因为属性名称冲突。尝试将您的属性更改为以下内容:

<attr name="radius" format="dimension" />
<attr name="border" format="dimension" />
<attr name="border_color" format="reference|color" />

<declare-styleable name="RoundImageView">
    <attr name="riv_radius" />
    <attr name="riv_border" />
    <attr name="riv_border_color" />
</declare-styleable>

<declare-styleable name="CircleImageView">
    <attr name="civ_border" />
    <attr name="civ_border_color" />
</declare-styleable>

然后通过 View 类型使用 View 属性。


推荐阅读