strings.xml中的Android变量
发布时间:2020-12-16 07:51:32 所属栏目:百科 来源:网络整理
导读:在某处我读了如何在 XML文档中使用变量.他们说这很简单,我想是的.我在 Android strings.xml文件中成功地使用了它.我一整天都在使用它,直到突然android停止解析它并停止将其视为变量. 我用这种方式使用它: resourcesstring name="some_string"string1/string
在某处我读了如何在
XML文档中使用变量.他们说这很简单,我想是的.我在
Android strings.xml文件中成功地使用了它.我一整天都在使用它,直到突然android停止解析它并停止将其视为变量.
我用这种方式使用它: <resources> <string name="some_string">string1</string> <string name="another_string"> {$some_string} trolololo </string> </resources> 并通过java访问它:getApplicationContext().getString(R.strings.another_string); getApplicationContext().getString(R.strings.another_string); 在我用来接收字符串的输出中: string1 trolololo 现在我只收到: {$some_string} trolololo 有谁知道什么是错的?我知道Android的XML可能与标准XML不同,但是它可以用于工作. Awww …感谢您的任何建议.
这将解决您的问题:
<resources> <string name="some_string">string1</string> <string name="another_string">@string/some_string trolololo</string> </resources> 现在getApplicationContext().getString(R.strings.another_string)的输出将是string1 trolololo. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |