在字符串资源中强制使用空格

在 Android 字符串资源中,如何强制使用空格?

例如,当我使用“ result”而不是“ result”时,我仍然在应用程序的文本视图中看到“ result”。

36604 次浏览

Did you try to surround your string with quotes? Maybe leading and trailing whitespaces are stripped automatically.

<string name="foo">" bar"</string>

See the example at https://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling in section "Escaping apostrophes and quotes".

As an alternative to the answer given by Andreas Klöber you can use this method:

<string name="foobar">foo \u0020 bar</string>

This utilizes the unicode space character (\u0020).

Just quote the value, like this

<string name="str_name">" Hello World!"</string>