Android 如何将空格字符放入 XML 中的字符串名称中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10862975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to put space character into a string name in XML?
提问by Andreas
i have defined some strings in the strings.xml
file. Now I need to put some extra space between some numbers in the string. When I type extra space characters this is not showing on the application though.
我在strings.xml
文件中定义了一些字符串。现在我需要在字符串中的一些数字之间添加一些额外的空格。当我输入额外的空格字符时,这不会显示在应用程序上。
Before:
前:
<string name="spelatonertext3">-4, 5, -5, 6, -6,
And if I put extra space like this:
如果我像这样放置额外的空间:
<string name="spelatonertext3">-4, 5, -5, 6, -6,
It just looks the same on the app. How can I make space characters into the XML string?
它在应用程序上看起来是一样的。如何将空格字符放入 XML 字符串?
回答by ρяσ?ρ?я K
to use white space in xml as string use  
. XML won't take white space as it is. it will trim the white space before setting it. So use  
instead of single white space
使用 xml 中的空格作为字符串使用 
。XML 不会按原样占用空白。它将在设置之前修剪空白。所以使用 
而不是单个空格
回答by K_Anas
Insert \u0020 directly in the XML for a blank you would like to preserve.
直接在 XML 中插入 \u0020 以获取要保留的空白。
<string name="spelatonertext3">-4, \u00205, \u0020\u0020-5, \u00206, \u0020-6,</string>
回答by saibaba vali
Android doesn't support keeping the spaces at the end of the string in String.xml file so if you want space after string you need to use this unicode in between the words.
Android 不支持在 String.xml 文件中保留字符串末尾的空格,因此如果您想在字符串后使用空格,则需要在单词之间使用此 unicode。
\u0020
\u0020
It is a unicode space character.
它是一个 unicode 空格字符。
回答by MShipman
As already mentioned the correct way to have a space in an XML file is by using \u0020
which is the unicode character for a space.
如前所述,在 XML 文件中使用空格的正确方法是使用\u0020
which 是空格的 unicode 字符。
Example:
例子:
<string name="spelatonertext3">-4,\u00205,\u0020-5,\u00206,\u0020-6</string>
Other suggestions have said to use  
or  
but there is two downsides to this. The first downside is that these are ASCII characters so you are relying on something like a TextView to parse them. The second downside is that  
can sometimes cause strange wrapping in TextViews.
其他建议说使用 
or 
但这有两个缺点。第一个缺点是这些是 ASCII 字符,因此您依赖于 TextView 之类的东西来解析它们。第二个缺点是 
有时会导致 TextViews 中出现奇怪的换行。
回答by Andrey
Space variants:
空间变体:
<string name="space_demo">| | | |</string>
| SPACE | THIN SPACE | HAIR SPACE |
| 空间 | 薄空间 | 头发空间|
回答by Surjit Singh
You can use following as well
您也可以使用以下内容
<string name="spelatonertext3"> "-4, 5, -5, 6, -6, "> </string>
Put anything in " "
(quotation) with space, and it should work
将任何东西放在" "
(引号)中并带有空格,它应该可以工作
回答by pcodex
This should work as well. Use quotes to maintain space
这也应该有效。使用引号来保持空间
<string name="spelatonertext3">"-4, 5, -5, 6, -6,"</string>
回答by maxxi
Put  
in string.xml file to indicate a single space in an android project.
放入 
string.xml 文件以指示 android 项目中的单个空格。
回答by Rakesh Jha
If you are trying to give Space Between 2 string OR In String file of android then do this in your string file . Implement this before your "String name" that you want to show. \u0020\u0020For E.g.. \u0020\u0020\u0020\u0020\u0020\u0020Payment
如果您尝试在 2 个字符串之间或在 android 的字符串文件中提供空间,请在您的字符串文件中执行此操作。在要显示的“字符串名称”之前实现它。 \u0020\u0020例如。 \u0020\u0020\u0020\u0020\u0020\u0020付款
回答by Sagar Chorage
As per your question if you want add spaces more than one in string resources their are many option to add spaces between character or word :
根据您的问题,如果您想在字符串资源中添加多个空格,他们有很多选项可以在字符或单词之间添加空格:
1.By default one space you can add directly in string resource file it working fine. but if give more than one space inside string resources file then it exclude that spaces. eg . -4, 5, -5, 6, -6,
1.默认一个空格,你可以直接在字符串资源文件中添加它工作正常。但是如果在字符串资源文件中给出一个以上的空格,则它会排除该空格。例如。-4, 5, -5, 6, -6,
If you want add more extra spaces inside string resource file then uses:- i. adding unicode after character like
<string name="test">-4,  5,  -5,  6,  -6,</string>
如果您想在字符串资源文件中添加更多额外的空格,请使用:- i. 在字符后添加unicode,如
<string name="test">-4,  5,  -5,  6,  -6,</string>
ii.you can use "\u0020"
ii.您可以使用“\u0020”
<string name="test">-4,\u0020\u0020 5,\u0020\u00205 -5,\u0020\u00205 6,\u0020\u00205 -6,</string>