android在style中使用自定义属性 error: style attribute not found.

时间:2022-11-02 13:34:41

异常:

Error:(128, 5) error: style attribute 'com.honghui0531.prebiotics.view:attr/item_right_icon_src' not found.


自定义属性文件 attrs.xml


    <!--自定义itemview的属性-->
<declare-styleable name="custromerItemView">

<!--左侧图片-->
<attr name="item_left_icon_src" format="reference"></attr>
<attr name="item_left_icon_width" format="integer"></attr>
<attr name="item_left_icon_height" format="integer"></attr>
<attr name="item_left_icon_visibility" format="enum">
<enum name="visible" value="0x00000000"></enum>
<enum name="invisible" value="0x00000004"></enum>
<enum name="gone" value="0x00000008"></enum>

</attr>


<!--中间文字-->
<!--左侧图片-->
<attr name="tv_item_content_text" format="reference"></attr>
<attr name="tv_item_content_text_color" format="reference"></attr>
<attr name="tv_item_content_text_size" format="integer"></attr>

<attr name="tv_item_content_visibility" format="enum">
<enum name="visible" value="0x00000000"></enum>
<enum name="invisible" value="0x00000004"></enum>
<enum name="gone" value="0x00000008"></enum>

</attr>


<!--右侧图片-->
<attr name="item_right_icon_src" format="reference"></attr>
<attr name="item_right_icon_width" format="integer"></attr>
<attr name="item_right_icon_height" format="integer"></attr>
<attr name="item_right_icon_visibility" format="enum">
<enum name="visible" value="0x00000000"></enum>
<enum name="invisible" value="0x00000004"></enum>
<enum name="gone" value="0x00000008"></enum>

</attr>


<!--中间文字-->
<!--左侧图片-->
<attr name="tv_item_desc_text" format="reference"></attr>
<attr name="tv_item_desc_text_color" format="reference"></attr>
<attr name="tv_item_desc_text_size" format="integer"></attr>

<attr name="tv_item_desc_visibility" format="enum">
<enum name="visible" value="0x00000000"></enum>
<enum name="invisible" value="0x00000004"></enum>
<enum name="gone" value="0x00000008"></enum>

</attr>
</declare-styleable>


在style中使用,不用加限定即可

 <!--mine setting item -->
<style name="mineSettingItemStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="tv_item_content_text_color">@color/black</item>
<item name="tv_item_desc_visibility">gone</item>
<item name="item_right_icon_src">@mipmap/more</item>
</style>