我想在项目中使用自定义组件,并且要将其添加到如下所示的枚举属性中,我该怎么做?

<com.abb.abbcustomcompanents.buttons.AbbButton
        android:id="@+id/abbBtn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:Type="How can i use enum here"
        />

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="abbButton">
        <attr name="Type" format="enum"/>
        <attr name="onAction" format="string"/>
    </declare-styleable>
</resources>

谢谢 !

最佳答案

例如:

<attr name="myProperty" format="enum">
         <enum name="None" value="0"/>
         <enum name="One" value="1"/>
         <enum name="Two" value="2"/>
         <enum name="Three" value="3"/>
</attr>

像这样使用:
<YourCustomView
    ...
    app:myProperty="One"/>

引用

https://stackoverflow.com/a/15231645/1329126

08-18 08:34
查看更多