【问题标题】:Why @string/ display on button too为什么@string/ 也显示在按钮上
【发布时间】:2014-06-05 08:54:18
【问题描述】:

这是我的主要/xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn_dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Activity_2"
android:onClick="onClick" />
<Button
android:id="@+id/btn_dialog_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Activity_3"
android:onClick="onClick" />
</LinearLayout>

这是 string.xml

<string name="app_name">mgdf</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="Activity_2">Activity2</string>
<string name="Activity_3">Activity3</string>

但它仍然显示我的按钮(图形界面)@string/Activity_2@string/Activity_3 相同

【问题讨论】:

  • 它在运行时显示什么?因为图形编辑器经常显示不正确的值/默认值。
  • 这看起来很好,也许你在运行时改变了一些东西
  • 尝试清理项目并重新构建它。

标签: android android-layout android-button


【解决方案1】:

您是否尝试重命名这些字符串?以小写字母或更具体的名称开头?

【讨论】:

    【解决方案2】:

    你的"string.xml" 真的叫"string.xml"吗?

    我认为如果是这样,您只需将其命名为 "strings.xml" 并且它应该可以工作;)

    【讨论】:

    • @DerGolem 它必须始终是strings.xml
    • @Aniruddha 如果你阅读过官方文档(是吗?)developer.android.com/guide/topics/resources/…,你就会知道The filename is arbitrary. The &lt;string&gt; element's name will be used as the resource ID.
    • 谢谢魔像!我不知道 =)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 2012-02-27
    • 2017-06-06
    • 2016-05-19
    • 1970-01-01
    相关资源
    最近更新 更多