【问题标题】:The strings.xml file in AndroidAndroid中的strings.xml文件
【发布时间】:2013-05-24 15:19:25
【问题描述】:

这里是一个 Android 菜鸟。

所以,我正在关注 Lars Vogel 的 this 指南(第 20 节)。我在谷歌修改后的Eclipse中启动了一个新的Android Application Project,并编辑了strings.xml,所以看起来是这样的:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Temperature Converter</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <color name="myColor">#F5F5F5</color>
    <string name="celsius">to Celsius</string>
    <string name="fahernheit">to Fahrenheut</string>
    <string name="calc">Calculate</string>

</resources>

(前3个字符串是默认的)

然后我使用图形布局将TextView 添加到activity_main.xml。我尝试使用图形布局更改TextView 的文本属性。对于一些我添加的新字符串没有显示在资源选择器中。

我只能在 3 个默认字符串之间进行选择。但字符串。

为什么?

(我也尝试过使用文本 xml 编辑器。它不起作用。)

谢谢!

【问题讨论】:

  • 移除颜色元素,清理并重建您的项目。如果你想要颜色元素,你必须在 values 中创建一个名为 colors 的文件
  • @blackbelt color 不是问题。颜色和字符串都是值资源,可以在 res/values 目录下的任何 .xml 文件中。

标签: java android xml eclipse string


【解决方案1】:

你试过清洁吗

   (Project > Clean ) 

然后重建你的项目?

  ( Project > Build Project)

【讨论】:

    【解决方案2】:

    首先,您的 strings.xml 中有一个颜色标签。它不属于那里。

    如果它没有帮助删除它:

    • 尝试保存所有文件
    • 清理你的项目
    • 确保没有任何编译错误
    • 确保以这种方式引用字符串:

      android:text="@string/calc"  
      

    【讨论】:

      【解决方案3】:

      您需要包含周围的标签,以便 android 识别它,并将其作为您的资源。

      <?xml version="1.0" encoding="utf-8"?>
      <resources>
          <string name="app_name">Temperature Converter</string>
          <string name="action_settings">Settings</string>
          <string name="hello_world">Hello world!</string>
          <string name="celsius">to Celsius</string>
          <string name="fahernheit">to Fahrenheut</string>
          <string name="calc">Calculate</string>
      </resources>
      

      【讨论】:

      • 我通过“编辑”检查了实际问题,他确实包含了这些标签,只是它们没有显示在他的问题中。我正确地格式化了他的问题。但你说的没错,所以 +1。
      【解决方案4】:

      正如黑带指出的那样,尝试删除“颜色”条目,看看它是否有效。可能是阻止 XML 解析器查看其他字符串条目。当然,还要检查整个 XML 文件的 sintaxis 是否正确。

      【讨论】:

        猜你喜欢
        • 2011-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多