use*_*240 6 java android string-concatenation string-formatting
我在 Toast 中显示错误消息strings.xml
。
像这样
mErrorMsgId=R.string.username_or_password_incorrectfull;
但现在我需要将消息连接起来R.string.add_selfhosted_blog
以避免翻译不一致。
阅读一些类似的问题,但无法弄清楚。
编辑:
我想在 username_or_password_incorrectfull 字符串中的单词 tap 之后连接 nux_add_selfhosted_blog ...
<string name="username_or_password_incorrectfull">The username or password you entered is incorrect
\- If you\'re a self hosted user, don\'t forget to tap **Add Self Hosted Site** and fill the URL field</string>
Run Code Online (Sandbox Code Playgroud)
<string name="nux_add_selfhosted_blog">Add self-hosted site</string>
我怎样才能做到这一点?
您不能直接连接R.string.username_or_password_incorrectfull
with R.string.add_selfhosted_blog
,因为它们不是String
实例本身,而是资源 ID 到strings.xml
. 您可以获取 2 个字符串,然后正常连接它们。
像这样的东西:
String string1 = getResources().getString(R.string.username_or_password_incorrectfull);
String string2 = getResources().getString(R.string.add_selfhosted_blog);
String combined = string1 + string2;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18166 次 |
最近记录: |