Re-using Android Custom enum xml attributes

后端 未结 1 861
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 04:15

I\'m defining a custom attribute in XML that is an enum.It looks something like this:


    

        
相关标签:
1条回答
  • 2021-02-01 04:48

    Just define the attribute outside of your control:

    <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"/>
        <enum name="Four" value="4"/>
        <enum name="Five" value="5"/>
        <enum name="Six" value="6"/>
        <enum name="Seven" value="7"/>
        <enum name="Eight" value="8"/> 
        <enum name="Nine" value="9"/>
        <enum name="Ten" value="10"/>
    </attr>
    

    Then just reuse that for all of your controls:

    <declare-styleable name="MyControl">
        <attr name="myProperty"/>
    </declare-styleable>
    
    <declare-styleable name="MyUnrelatedControl">
        <attr name="myProperty"/>
    </declare-styleable>
    
    0 讨论(0)
提交回复
热议问题