多种字体支持多国语言 [英] Multiple fonts for multiple languages

查看:974
本文介绍了多种字体支持多国语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到一个情况,同时开发一个应用程序在那里我可以显示在文本视图不同的语言。目前我展示一些用字体/字体是这样的:

I have recently come across a situation while developing an app where i have to display different languages in text view . currently I am displaying few using fonts/typeface like this :

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("এই ইংরেজি নয়");

其优良的我的问题是我必须支持一些20种不同的语言,然后事情就会变得非常乏味,当我应用此不同的活动。任何替代的方式来实现。

its fine my question is that i have to support for some 20 different languages then things will become very tedious when i apply this in different activities . Any alternative way to achieve.

推荐答案

您要做的就是创建一个类和接入公共函数将返回你的TextView与要假设Font对象。

You do is to create a class and a function with access public that will return you TextView Object with the Font that you want to suppose.

    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

这篇关于多种字体支持多国语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆