【问题标题】:how do i store android constants in a strings.xml file?如何将 android 常量存储在 strings.xml 文件中?
【发布时间】:2014-10-14 07:54:43
【问题描述】:

我想用这样的东西:

<TextView
            android:id="@+id/text"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="@string/textview_gravity" >

然后在我的 strings.xml 中

有这样的东西:

<string name="textview_gravity" >bottom|right</string>

有什么想法吗?这甚至可能吗?

【问题讨论】:

  • 相应地更改您的代码中的重力。在 xml 中,我认为这是不可能的。

标签: android xml configuration


【解决方案1】:

我不相信你可以在 android 中以这种方式使用字符串常量。我相信您只能使用存储在需要字符串字段的属性字段中的字符串常量,例如:

        android:text="@string/some_string" 

【讨论】:

    【解决方案2】:

    不,这是不可能的。你应该使用styles.xml 来处理这类事情

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多