Displaying Unicode Symbols in Android

Eventually in Android, you will need to display a non-ASCII character. You know, characters like the cents or plus minus symbols. They exist in Unicode, but not normally on American keyboards.  And surprisingly there isn’t much information on how to do it.

Since I also do web development, I know that HTML has support for the full gallery of Unicode symbols. In order to display the cents symbol, the HTML is: &cents; and for the plus minus symbol it is: ±

Android has a class, Html, which has static methods for converting strings to and from HTML. For us, the method of interest is: fromHtml. This method: returns displayable styled text from the provided HTML string. Here is how we use it:

static String plusMinusSymbol = Html.fromHtml(“±”).toString();

Now, plusMinusSymbol, holds the string for the symbol, it can be used any where a String is expected. You can use the HTML for any Unicode symbol.


One thought on “Displaying Unicode Symbols in Android

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s