Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
136 views
in Technique[技术] by (71.8m points)

android - Using Enums as Custom XML Attributes

I want to use custom components in my project and i want to add it to enum attributes like below , how can i do that ?

<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>

Thank you !

question from:https://stackoverflow.com/questions/15943745/using-enums-as-custom-xml-attributes

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Ex :

<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>

Use like this:

<YourCustomView
    ...
    app:myProperty="One"/>

Reference

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...