子模块自定义属性AndroidStudio有棉绒问题

时间:2018-09-19 02:58:58

标签: android android-layout android-studio

当我在这样的子模块上声明attrs时:

<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无法自动提示:

enter image description here

通过这种方式,当我运行应用程序时,效果很好。只是具有皮棉通知和属性不提示。

2 个答案:

答案 0 :(得分:0)

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

<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属性。

答案 1 :(得分:0)

我有两种方法来解决名称空间前缀问题。

  1. 在xml中添加忽略代码。 tools:ignore="MissingPrefix"

  2. 取消选中Preferences -> Edit -> Inspection -> Missing Android XML namespace

但是属性仍然不提示。