Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display special characters (like –) in the TextView?

How can I display special characters(like – ") in a TextView?

like image 973
yital9 Avatar asked Feb 22 '12 18:02

yital9


People also ask

How do I show hidden ascii characters in a text file?

Go to View Menu > Select Show Symbol > Select Show All Characters . It displays all hidden characters in the opened file.

How do you text special characters?

Typing Special CharactersPress and hold the key associated with the unique character, a pop-up appears. Place the finger on the unique character you want. The special character will appear. Press hold the N key to get an N with a tilde over it.


4 Answers

You can use the Html.fromHtml() to handle HTML formatted text into a Spannable that TextView can display.

like image 158
draksia Avatar answered Nov 15 '22 18:11

draksia


If you know the Unicode value, you can display any UTF-8 character. Example, for " you would have &\#0034;.

See Unicode Characters (at Code Table) for more information.

like image 22
Knossos Avatar answered Nov 15 '22 19:11

Knossos


I've implemented this solution.

Activity class:

textView.setText( getString(R.string.author_quote, "To be or not to be", "Shakespeare") )

strings.xml:

<string name="author_quote">&#171; %1$s &#187; - %2$s</string>

HTML chars are written directly in strings.xml, no additional Html.fromHtml() is needed. It works fine on all my devices.

like image 28
voghDev Avatar answered Nov 15 '22 20:11

voghDev


I've written a custom method that will convert all unicode from hexa to integer and replaces from actual string. So that text view can read is as a unicode. have a look ,this will solve your problem...

public String unecodeStr(String escapedString) {

    try {
        String str;
        int from = 0;
        int index = escapedString.indexOf("\\u", 0);
        while (index > -1) {
            str = escapedString.substring(index, index + 6).replace("\\u", "");
            try {
                Integer iI = Integer.parseInt(str, 16);
                char[] chaCha = Character.toChars(iI);
                escapedString = escapedString.replaceFirst(str, String.valueOf(chaCha));
            } catch (Exception e) {
                CustomLog.e("error:", e.getMessage());
            }
            from = index + 3;
            index = escapedString.indexOf("\\u", from);
        }

        escapedString = escapedString.replace("\\u", "");
    } catch (Exception e) {
        CustomLog.info("warnning", "emoji parsing error at " + escapedString);
    }

    return escapedString;
}
like image 43
Prinkal Kumar Avatar answered Nov 15 '22 19:11

Prinkal Kumar