Bonjour,
Je veux afficher un texte en japonais dans un textview (en Kanjis, caractères unicode entre 0x3500 et 0x9FB0, à la louche). C'est apparemment un topic classique et les recherches que j'ai fait m'ont donné la solution suivante :
1 - copier un fichier de fonte .ttf dans le répertoire /assets/fonts du projet
2 - l'utiliser via:
Dans lequel kanji_char est l'ID de mon textview destiné à afficher le texte en japonais. Il est défini dans un fichier xml par :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/TakaoPMincho.TTF"); TextView t = (TextView)findViewById(R.id.kanji_char); t.setTypeface(tf); s = Character.toString((char)code); // code est le code unicode hexa du caractère japonais (Kanji) t.setText(s); t.setTypeface(tf); // j'ai aussi essayé de le mettre avant setText ...
Manque de bol, ca ne marche pas; Je m'explique : j'ai bien des Kanjis japonais qui s'affichent, mais c'est apparemment ceux de la fonte par défaut. J'ai beau changer de fichier de fonte, le résultat est le même.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 <!-- ?xml version="1.0" encoding="utf-8"?> --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/kanji_framenb" android:gravity="center" android:textColor="#550000" android:text="@string/string_keyword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="15sp" /> <TextView android:id="@+id/kanji_char" android:gravity="center" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="0dip" android:textSize="90sp" /> <TextView android:id="@+id/kanji_onp" android:textColor="#007000" android:text="@string/string_keyword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="15sp" /> <TextView android:id="@+id/kanji_kunp" android:textColor="#106000" android:text="@string/string_keyword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="15sp" /> <TextView android:id="@+id/kanji_mean1" android:textColor="#0000FF" android:text="@string/string_keyword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="15sp" /> <TextView android:id="@+id/kanji_mean2" android:textColor="#0000FF" android:text="@string/string_keyword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="15sp" /> <Button android:id="@+id/back" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/back" /> <Button android:id="@+id/next" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/next_kanji" /> </LinearLayout>
Merci d'avance pour vos suggestions ...
Olivier
Partager