【问题标题】:Set value of enum in xml from resource从资源中设置 xml 中枚举的值
【发布时间】:2013-05-29 08:34:29
【问题描述】:

我正在为 enum 类型的自定义视图构建自定义属性。
我知道每个可选值都必须带有名称和值。我希望该值将从另一个资源中给出,如以下示例所示(在文件 attrs.xml 中):

整数资源:

<integer name="example">0</integer>

样式声明:

<declare-styleable name="FontStyleTextView" format="enum">
    <attr name="typeFace">
        <enum name="name1" value="@integer/example"/>
        <enum name="name2" value="1"/>
    </attr>
</declare-styleable>

我得到的错误是:

error: Tag <enum> or <flag> 'value' attribute must be a number, not "@integer/example"

是否有任何可能的方式为 value 字段赋予另一个资源的值?

【问题讨论】:

    标签: android android-custom-view


    【解决方案1】:

    没有。就像错误说“属性必须是数字”一样,您正在尝试使用参考。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      • 2011-11-14
      • 2018-10-05
      • 2016-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多