LoginSignup
18
19

More than 5 years have passed since last update.

TextViewで濁点の表示が崩れる

Posted at

TextViewに濁点入り文字列を渡すと表示が崩れたのでメモ。
Unicodeの正規化方式には4種類あるそうだが、今回はNFD正規化した文字列で問題が起きており、それをNFC正規化することで解決した。

NFDな文字列を表示する場合と、それをNFCな文字列に変換して表示する場合で結果が違う。

int[] nfdCodePoints = new int[]{
        0x30C8, //ト
        0x3099, //゛
        0x30A4, //イ
        0x30C4, //ツ
};
String text = new String(nfdCodePoints, 0, nfdCodePoints.length);

// NFD文字列を表示
textView.setText(text);

// NFC文字列を表示
textView2.setText(Normalizer.normalize(text, Normalizer.Form.NFC));
Device / OS TextView
Nexus5 / 5.1.1 5.1.1.png
Nexus5 / 4.4.4 4.4.4.png

Android4.4.4では問題なかったが、Android5系から発生するようになった、のかな。
ネイティブでも対応できるが今回はサーバサイドで変換してもらった。

参考

文字コード地獄秘話 第3話:後戻りの効かないUnicode正規化

18
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19