gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-28 23:56:34 25 4
gpt4 key购买 nike

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

<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

关于android - 使用枚举作为自定义 XML 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15943745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com