How can I display special characters(like – "
) in a TextView?
Go to View Menu > Select Show Symbol > Select Show All Characters . It displays all hidden characters in the opened file.
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.
You can use the Html.fromHtml()
to handle HTML formatted text into a Spannable
that TextView
can display.
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.
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">« %1$s » - %2$s</string>
HTML chars are written directly in strings.xml, no additional Html.fromHtml() is needed. It works fine on all my devices.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With