2013-03-19 3 views
1

J'ai récemment rencontré une situation lors du développement d'une application où je dois afficher différentes langues en mode texte. actuellement je suis affichant peu à l'aide polices/caractères typographiques comme ceci:Plusieurs polices pour plusieurs langues

Typeface tf = Typeface.createFromAsset(this.getAssets(), 
       "DroidHindi.ttf"); 
     TextView textView1 = (TextView) findViewById(R.id.textView2); 
     textView1.setTypeface(tf); 
     textView1.setText("कचजड, कचजड"); 

     Typeface tf1 = Typeface.createFromAsset(this.getAssets(), 
       "asunaskh.ttf"); 
     TextView textView = (TextView) findViewById(R.id.textView1); 
     textView.setTypeface(tf1); 
     textView.setText("یہ انگریزی نہیں"); 

     Typeface tf2 = Typeface.createFromAsset(this.getAssets(), 
       "Banglafont.ttf"); 
     TextView textView2 = (TextView) findViewById(R.id.textView3); 
     textView2.setTypeface(tf2);// এই ইংরেজি নয় 
     textView2.setText("এই ইংরেজি নয়"); 

sa belle ma question est que je dois soutenir quelques 20 langues différentes alors les choses deviendront très fastidieux quand j'appliquer dans différents Activités . Toute autre façon de réaliser.

Répondre

4

Vous devez créer une classe et une fonction avec access public qui vous renverra l'objet TextView avec la police que vous voulez supposer.

TextView public SetLanguage(TextView tv,string type) 
    { 
    TextView newtv = tv; 
    Typeface tf; 
    switch(type) 
    { 
     case "urdu": 
     tf = Typeface.createFromAsset(this.getAssets(),"urdu.ttf"); 
     break; 
     case "hindi": 
     tf = Typeface.createFromAsset(this.getAssets(),"hindi.ttf"); 
     break; 
    // up so on     

    } 
    newtv.setTypeface(tf); 
    return newtv; 
} 
    // and call it any where.. 
TextView textView1 = (TextView) findViewById(R.id.textView2); 
textView1 = classobj.SetLanguage(textView1,"urdu"); 
//assign string of text to it 
4

Initialisez vos polices de caractères lorsque l'application démarre et créez une méthode qui prend n'importe quelle vue et définit la police en fonction de la langue.

+0

juste ce que j'ai fait dans mon application, parfait –