Android:如何使用泰米尔语字体

时间:2011-08-22 05:25:52

标签: android layout fonts textview typeface

这是我的tamil html unicode字符串

முதல்பக்கக்திகள்

我正在使用此代码:

    TextView text=(TextView)findViewById(R.id.text); // initialize to your textview
    Typeface tf = Typeface.createFromAsset(this.getAssets(),"fonts/tamil.ttf");
    text.setTypeface(tf);
    text.setText("முதல் பக்க செய்திகள்");

在Android中,这可能吗?

4 个答案:

答案 0 :(得分:12)

首先,您必须了解Android操作系统中没有泰米尔语语言支持(除了少数三星和SE手机),直到ICS(4.0)。即便如此,它还有虫子,并且Jelly Bean(4.2)提供了全面的支持。

如果您在应用中使用Unicode Tamil字体,则只会看到框。原因是系统中没有泰米尔语字体。

这个解决方案有一个解决方法。您所要做的就是download the Bamini font并将其放在您的资源文件夹中。并使用字体Bamini创建TypeFace并将其设置为TextView。

Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/Bamini.ttf");
customText1.setTypeface(font1);

现在使用converter to convert Unicode font into Bamini编码。而不是Unicode文本将转换后的Bamini编码脚本提供给setText方法。

如果您讨厌所有这些手动编码转换,请查看此library

正如我在上面所说,如果您想在运行应用程序时动态更改编码,那么我为Android编写了consider using the library。该库将帮助您将Unicode字符串转换为Bamini,TSCII,TAB,TAM和Anjal。

设置非常简单。您只需将库导入Android项目并按如下方式调用库即可。

// Initialise the Typeface (assumes TSCII, Bamini, Anjal, TAB or TAM font located inside assets/fonts folder)
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/mylai.ttf");
// Initialises the TextView
TextView tv = (TextView)findViewById(R.id.textView1);
//Setting the Typeface
tv.setTypeface(tf);
//Magic happens here ;) encoding conversion
String TSCIIString = TamilUtil.convertToTamil(TamilUtil.TSCII, "வணக்கம் அன்ரொயிட்");
//Setting the new string to TextView
tv.setText(TSCIIString);

库中提供了sample app。查看应用程序如何使用库将Unicode字符串转换为Bamini,TAB,TAM,TSCII和Anjal。

请务必阅读我关于如何解决Tamil on Android Native apps and WebViews here in this Answer的全面答案。

答案 1 :(得分:2)

谢谢Mayu ..好消息...

Jeeva,..只需查看此页面的来源http://www.islamkalvi.com/web/unicode_to_bamini.htm ..您将获得一个可用于将Unicode字体转换为Bamini编码的JavaScript函数。

答案 2 :(得分:1)

要将unicode转换为TSCII,请参阅ThamiZha's TamilVisai。他们已经发布了泰米尔语的InputMethod,它的开源。以下是其申请source code的链接。有一个名为UnicodeUtil的类可以动态地将Unicode转换为TSCII。

答案 3 :(得分:0)

我已将Bamini.ttf用于tamil字体。你需要使用bamini转换器将泰米尔语字体转换为unicode。获取在泰米尔语中执行应用程序的源代码。请访问以下网站

http://www.tamilvizhi.com/sample-android-application-in-tamil-book-applicationandroid-application-development-source-code/

相关问题