无法显示@string

时间:2015-04-17 07:20:30

标签: android string

strings.xml:

    <string name="change">Change</string>
    <string name="Pleasechoosesubject">Please choose subject</string>
    <string name="onlyprovide">We provide only English version</string>
    <string name="action_home">News</string>
    <string name="creators">Creators</string>
    <string name="action_language">中文</string>
    <string name="version">Version</string>
    <string name="eEmailus">Email Us</string>
    <string name="contactus">Contact Us</string>
    <string name="About">About</string>
    <string name="ICTQuiz">ICT Quiz</string>
    <string name="EnglishQuiz">English Quiz</string>
    <string name="MathQuiz">Math Quiz</string>
    <string name="Tutorial">Tutorial</string>
    <string name="Opinion">Opinion</string>
    <string name="Home">Home</string>
    <string name="Help">Help</string>
    <string name="Exit">Exit</string>

其他活动的xml:

  <TextView
        android:id="@+id/t1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:paddingBottom="10dip"
        android:paddingLeft="7dip"
        android:paddingTop="9dip"
        android:text="@string/leaveopinion"
        android:textSize="20sp" />

为什么我不能直接显示单词而不是@ String / xxxx

http://i.stack.imgur.com/BfPdW.png

1 个答案:

答案 0 :(得分:0)

leaveopinion不在res/values/strings.xml中。 首先,您需要将它添加到strings.xml中。 像这样:

string name="leaveopinion">your_text</string>

要显示真实文本而不是@string/XXX,您需要刷新your_activity.xml。

当你做了以上所有事情时,它应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="change">Change</string>
    <string name="Pleasechoosesubject">Please choose subject</string>
    <string name="onlyprovide">We provide only English version</string>
    <string name="action_home">News</string>
    <string name="creators">Creators</string>
    <string name="action_language">中文</string>
    <string name="version">Version</string>
    <string name="eEmailus">Email Us</string>
    <string name="contactus">Contact Us</string>
    <string name="About">About</string>
    <string name="ICTQuiz">ICT Quiz</string>
    <string name="EnglishQuiz">English Quiz</string>
    <string name="MathQuiz">Math Quiz</string>
    <string name="Tutorial">Tutorial</string>
    <string name="Opinion">Opinion</string>
    <string name="Home">Home</string>
    <string name="Help">Help</string>
    <string name="Exit">Exit</string>

    <!-- this line -->
    <string name="leaveopinion">your_text</string>

</resources>

并检查您是否已将strings.xml放入res/values/文件夹。

希望它有所帮助!

如果不起作用,请尝试重建项目。