Android TextView 中的特殊字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23608471/
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
Special characters in a TextView
提问by Alireza
I want to show the "?"character in an Android TextView, but it shows [] instead.
我想显示“?” Android TextView 中的字符,但它显示 [] 。
This is my code:
这是我的代码:
txtCatname.setText("?");
How can I display this symbol correctly?
如何正确显示此符号?
回答by Phant?maxx
You can use an Unicode code: http://unicode-table.com/en/.
您可以使用 Unicode 代码:http: //unicode-table.com/en/。
Such as:
如:
txtCatname.setText("\u266b");
or alternatively use an iconic font, such as font awesome:
http://fortawesome.github.io/Font-Awesome/
或者使用标志性的字体,例如 font awesome:http:
//fortawesome.github.io/Font-Awesome/
Use this alternative (or any other iconic font you like), in case this character isn't supported (not all Unicode characters are supported).
如果不支持此字符(并非所有 Unicode 字符都受支持),请使用此替代方法(或您喜欢的任何其他标志性字体)。
回答by ViVekH
Try this:
尝试这个:
String str = "?";
byte spbyte[] = str.getBytes("UTF-8");
str = new String( spbyte,"UTF-8");
txtCatname.setText(str);
If it doesn't work, try this:
如果它不起作用,请尝试以下操作:
String str = "?";
txtCatname.setText(Html.fromHtml(str));
回答by 18446744073709551615
If nothing else helps, you can either:
如果没有其他帮助,您可以:
use a custom font (e.g. http://www.tutorialspoint.com/android/android_custom_fonts.htmor Add custom font for complete android application) or
add an image: How to add image in a TextView text?
回答by MarcoP
That is common when the source file is encoded as ANSI. Converting the source file as UTF-8 (without BOM) will likely solve the issue.
当源文件被编码为 ANSI 时,这是很常见的。将源文件转换为 UTF-8(没有 BOM)可能会解决这个问题。
回答by Nouman Ch
This seems pretty simple now:
这现在看起来很简单:
Simply go to unicode listand choose your unicode and copy go it.
Go to strings.xml and paste it.
This will paste the unicode character instead of it's code and use it in your xml as a normal string.
只需转到unicode 列表并选择您的 unicode 并复制即可。
转到strings.xml 并粘贴它。
这将粘贴 unicode 字符而不是它的代码,并在您的 xml 中将其用作普通字符串。
Hope this will help you.
希望这会帮助你。
回答by ARMEL FOPA
Simply append the symbol as a string in your string.xml By adding double quotes to the special character.
通过在特殊字符上添加双引号,只需将该符号作为字符串附加到 string.xml 中即可。