1

I discovered today that Android can't display a small handful of Japanese characters that I'm using in my Japanese-English dictionary app.

The problem comes when I attempt to display the character via TextView.setText(). All of the characters below show up as blank when I attempt to display them in a TextView. It doesn't appear to be an issue with encoding, though - I'm storing the characters in a SQLite database and have verified that Android can understand the characters. Casting the characters to (int) retrieves proper Unicode decimal escapes for all but one of the characters:

String component = cursor.getString(cursor.getColumnIndex("component"));
Log.i("CursorAdapterGridComponents", "Character Code: " + (int) component.charAt(0) + "(" + component + ")");

I had to use Character.codePointAt() to get the decimal escape for the one problematic character:

int codePoint = Character.codePointAt(component, 0);

I don't think I'm doing anything wrong, and as String's are by default UTF-16 encoded, there should be nothing preventing them from displaying the characters.

Below are all of the decimal escapes for the seven problematic characters:

  1. ⺅ Character Code: 11909(⺅)
  2. ⺌ Character Code: 11916(⺌)
  3. ⺾ Character Code: 11966(⺾)
  4. ⻏ Character Code: 11983(⻏)
  5. ⻖ Character Code: 11990(⻖)
  6. ⺹ Character Code: 11961(⺹)
  7. Character Code: 131490()

Plugging the first six values into http://unicode-table.com/en/ revealed their corresponding Unicode numbers, so I have no doubt that they're valid UTF-8 characters.

The seventh character could only be retrieved from a table of UTF-16 characters: http://www.fileformat.info/info/unicode/char/201a2/browsertest.htm. I could not use its 5-character Unicode number in setText() (as in "\u201a2") because, as I discovered earlier today, Android has no support for Unicode strings past 0xFFFF. As a result, the string was evaluated as "\u201a" + "2". That still doesn't explain why the first six characters won't show up.

What are my options at this point? My first instinct is to just make graphics out of the problematic characters, but Android's highly variable DPI environment makes this a challenging proposition. Is using another font in my app an option? Aside from that, I really have no idea how to proceed.

4

1 回答 1

3

在我的应用程序中使用另一种字体是一种选择吗?

当然。查找您已获准与您的应用程序一起分发并具有这些字符的字体。将字体打包到您的assets/目录中。为该字体创建一个Typeface对象。使用setTypeface()on将该字体应用于必要的小部件TextView

这是一个示例应用程序,演示了将自定义字体应用于TextView.

于 2013-09-06T00:03:58.320 回答