使用枚举作为自定义XML属性

Tal*_*lha 42 android android-custom-view android-layout

我想在我的项目中使用自定义组件,我想将它添加到下面的枚举属性,我该怎么做?

<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>
Run Code Online (Sandbox Code Playgroud)

谢谢 !

San*_*r V 70

例如:

<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>
Run Code Online (Sandbox Code Playgroud)

使用这样:

<YourCustomView
    ...
    app:myProperty="One"/>
Run Code Online (Sandbox Code Playgroud)

参考

/sf/answers/1066215181/