在Android的strings.xml中的变量 [英] Android variables in strings.xml

查看:293
本文介绍了在Android的strings.xml中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾读到如何将XML文档中使用的变量。他们说,这很简单,我想这是。我成功地用它在Android中的strings.xml文件的方式。我用这种方式了整整一天,直到突然停止的android分析它,并停下来把它当作一个变量。

Somewhere I read how to use variables in XML document. They said it's very simple and I guess it was. I successfully used it that way in Android strings.xml file. I was using it that way the whole day until suddenly android stopped to parse it and stopped to treat it like a variable.

我用它是这样的:

<resources>
<string name="some_string">string1</string>
<string name="another_string"> {$some_string} trolololo </string>
</resources>

和Java中访问它通过:getApplicationContext()的getString(R.strings.another_string);

and in java accessing it through: getApplicationContext().getString(R.strings.another_string);

getApplicationContext().getString(R.strings.another_string);

在输出I用来接收字符串,如:

In the output I used to receive string like:

string1 trolololo

和目前我只收到:

{$some_string} trolololo

没有人有任何的想法有什么不好?我知道,Android的XML可能比标准的XML不同,但它曾经的工作。呀,感谢您的任何建议。

Does anyone have any idea what is wrong? I know that Android's XML may differ than standard XML, but IT USED TO WORK. Awww... Thanks for any advice.

推荐答案

这将解决你的问题:

<resources>
    <string name="some_string">string1</string>
    <string name="another_string">@string/some_string trolololo</string>
</resources>

现在的输出 getApplicationContext()的getString(R.strings.another_string)字符串1 trolololo

这篇关于在Android的strings.xml中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆