1

我正在为 android 3.0 创建基于流的波斯语应用程序。它在字符的位置显示“正方形”گ ڪ ڙ ا

如何添加对波斯语的支持?

4

3 回答 3

2

这意味着您的设备使用的字体不支持波斯语字符(因此squares)。您需要找到更好的字体并在您的应用程序中使用它(请参阅http://developer.android.com/reference/android/graphics/Typeface.html文档)

于 2013-08-30T12:06:50.347 回答
1

您需要使用Typeface来支持其他字体。

创建一个名为assets的新文件夹(如果它不存在)。在其中创建一个名为fonts的新文件夹(只是为了您的简单)

从 Internet 下载“farsi”字体并将其复制到字体文件夹中。

在您的类文件中create a String to the path of the font. 并使用此代码

    Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
    txt1.setTypeface(tf);

编辑:某些字体可能在一部手机中支持,而在其他手机中可能不支持。例如,我的 xperia 支持印地语字体,但我的朋友 S2 不支持。

于 2013-08-30T12:24:01.360 回答
0

首先从任何一个链接下载 ttf 文件,

http://www.neda.net.ir/downloads/fonts/persian.ttf

http://alefba.us/wp-content/plugins/download-monitor/download.php?id=farsifonts-0.4.zip

 copy the ttf file into assets folder in your project,,

首先在单击按钮的代码中选择语言代码为波斯语

button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Locale myLocale = new Locale("fa"); 
            Resources res = getResources(); 
            DisplayMetrics dispmetrics = res.getDisplayMetrics(); 
            Configuration conf = res.getConfiguration(); 
            conf.locale = myLocale; 
            res.updateConfiguration(conf, dispmetrics);
            String current_locale = getResources().getConfiguration().locale.getDisplayName();
            System.out.println(current_locale);
            Intent refresh = new Intent(getBaseContext(), MainActivity.class);
            startActivity(refresh);
        }
    });

然后在下面, setContentView(R.layout.activity_main);

              implement this code,,to get the typeFace done

            String current_locale = getResources().getConfiguration().locale.getDisplayName();
    System.out.println("-----"+current_locale);

    if(current_locale.equals("Persian"))
    {

    Typeface font1 = Typeface.createFromAsset(getAssets(), "persian.ttf");
    b1.setTypeface(font1);
    }

这个解决方案绝对有效,方括号出现在您的手机中的原因是您的手机上没有安装波斯语 Unicode,如果您想安装波斯语字体,您的手机必须植根

- 谢谢

于 2013-08-30T13:21:58.233 回答