一个人能结合安卓资源字符串为新的字符串? [英] Can one combine android resource strings into new strings?

查看:101
本文介绍了一个人能结合安卓资源字符串为新的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安卓允许创建资源字符串的别名,如:

Android allows to create aliases of resource strings like:

<resources>
 <string name="foo">somestring</string>
 <string name="bar">@string/foo</string>
</resources>

指资源栏成为其别名名为foo。

by which the resource "bar" becomes an alias for the resource named "foo".

我会为我的应用程序是一个可能性,结合现有资源preFIX有不同的后缀,即把它扩大,如:

What I would for my app is a possibility to combine an existing resource prefix with different suffixes, i.e. to extend it like:

<resources>
 <string name="foo">foo</string>
 <string name="bar">@string/foo+bar</string> 
 <string name="else">@string/foo+else</string> 
</resources>

在资源栏将产生字符串FOOBAR。它明确表示,+不在这里工作了,但有一些其他的选择来实现这样的字符串连接,这样就可以定义一串一串资源都有一个共同的preFIX的?

where the resource "bar" would yield the string "foobar". Its clear that '+' doesn't work here but is there some other option to achieve such a string concatenation, so that one could define a bunch of string resources that have a common prefix?

我知道当然,我可以在运行时做了这样的资源字符串连接,但静态定义它们的资源将显得那样更优雅,更简单。

I realize of course that I could do such resource string concatenation at runtime but defining them statically in the resources would seem so much more elegant and simpler.

迈克尔

推荐答案

没有,这是不可能的。 你可以只用&LT;字符串名称=酒吧&gt;这是我的%S&LT; /串&GT; 然后用的String.Format()在你的应用程序,以填补与变量,例如

No, it's not possible. You can just use <string name="bar">This is my %s</string> and then use String.format() in your app to fill in the variable with for example

getResources().getString(R.string.foo);

这篇关于一个人能结合安卓资源字符串为新的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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