Special characters in a TextView

前端 未结 6 822
孤城傲影
孤城傲影 2020-12-09 20:35

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

This is my code:

txtCatname.setText(\"♫\");


        
相关标签:
6条回答
  • 2020-12-09 21:24

    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. 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.

    0 讨论(0)
  • 2020-12-09 21:27

    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).

    0 讨论(0)
  • 2020-12-09 21:27

    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.

    0 讨论(0)
  • 2020-12-09 21:31

    If nothing else helps, you can either:

    1. use a custom font (e.g. http://www.tutorialspoint.com/android/android_custom_fonts.htm or Add custom font for complete android application ) or

    2. add an image: How to add image in a TextView text?

    0 讨论(0)
  • 2020-12-09 21:32

    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));
    
    0 讨论(0)
  • 2020-12-09 21:38

    Simply append the symbol as a string in your string.xml By adding double quotes to the special character.

    0 讨论(0)
提交回复
热议问题