我是Android新手。
所以,我遵循Lars Vogel的指南(第20节)。我在Google修改过的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编辑器。)
谢谢!
你试过清洗了吗
(Project > Clean )
,然后重建您的项目?
( Project > Build Project)
首先,在您的strings.xml中有一个颜色标记。它不属于那里。
如果没有帮助就删除它:
- 尝试保存所有文件
- 清理项目
- 确保没有任何编译错误
-
确保以这种方式引用字符串:
android:text="@string/calc"
你需要包括周围的标签,以便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>
正如blackbelt指出的那样,尝试删除color条目,看看它是否有效。可能是阻止XML解析器看到其他字符串条目。当然,还要检查整个XML文件的格式是否正确。