Special characters Android TextView

2019-01-23 18:53发布

I want to show the "♫" character in an Android TextView, but it shows [] instead.

This is my code:

txtCatname.setText("♫");

How can I display this symbol correctly?

5条回答
混吃等死
2楼-- · 2019-01-23 19:11

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.

查看更多
在下西门庆
4楼-- · 2019-01-23 19:13

This seems pretty simple now:

  • Simply go to unicode list and choose your unicode and copy go it.

  • Go to strings.xml and paste it. enter image description here This will paste the unicode character instead of it's code and use it in your xml as a normal string.

Hope this will help you.

查看更多
祖国的老花朵
5楼-- · 2019-01-23 19:15

You can use an Unicode code: 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/

Use this alternative (or any other iconic font you like), in case this character isn't supported (not all Unicode characters are supported).

查看更多
够拽才男人
6楼-- · 2019-01-23 19:18

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));
查看更多
登录 后发表回答