简体   繁体   English

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

[英]Android : how to use Tamil font

This is my tamil html unicode string 这是我的泰米尔语html unicode字符串

முதல் பக்க செய்திகள் முதல்பக்கக்திகள்

I am using this code: 我正在使用此代码:

    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("முதல் பக்க செய்திகள்");

In Android, is this possible? 在Android中,这可能吗?

First of all you have to understand that there is no Tamil Language support in Android OS (except few Samsung & SE mobiles) till ICS(4.0). 首先,您必须了解Android操作系统中没有泰米尔语语言支持(除了少数三星和SE手机),直到ICS(4.0)。 Even then it had bugs and full support is provided with Jelly Bean (4.2). 即便如此,它还有虫子,并且Jelly Bean(4.2)提供了全面的支持。

You will only see boxes if you use Unicode Tamil font in your app. 如果您在应用中使用Unicode Tamil字体,则只会看到框。 Reason is there are no Tamil fonts in the system. 原因是系统中没有泰米尔语字体。

There is a work around for this solution. 这个解决方案有一个解决方案。 All you have to do is, download the Bamini font and place it in your assets folder. 您所要做的就是下载Bamini字体并将其放在您的资源文件夹中。 And create TypeFace with the font Bamini and set it to the TextView. 并使用字体Bamini创建TypeFace并将其设置为TextView。

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

Now use a converter to convert Unicode font into Bamini encoding. 现在使用转换器将Unicode字体转换为Bamini编码。 instead of the Unicode text provide the converted Bamini encoded script into the setText method. 而不是Unicode文本提供转换后的Bamini编码脚本到setText方法。

If you hate all these manual encoding conversion then check out this library 如果您讨厌所有这些手动编码转换,请查看此

As I said in above line, if you like to change the encoding dynamically while running the application then consider using the library I wrote for Android. 正如我在上面所说,如果你想在运行应用程序时动态更改编码,那么考虑使用我为Android编写的库 This library will help you to convert Unicode String to Bamini, TSCII, TAB, TAM and Anjal. 该库将帮助您将Unicode字符串转换为Bamini,TSCII,TAB,TAM和Anjal。

Set up is very simple. 设置很简单。 All you have to do is simply import the library into your Android project and call the library as below. 您只需将库导入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);

There is a sample app available along with the library. 有一个示例应用程序以及库。 Check out the app on how the library is utilised to convert the Unicode String to Bamini, TAB, TAM, TSCII and Anjal. 查看应用程序如何使用库将Unicode字符串转换为Bamini,TAB,TAM,TSCII和Anjal。

Please make sure to read my comprehensive answer on how to tackle Tamil on Android Native apps and WebViews here in this Answer . 请务必阅读本答案中关于如何在Android Native应用程序和WebViews上解决泰米尔问题的全面答案。

Thanks Mayu.. Nice info... 谢谢Mayu ..好消息......

Jeeva,.. Just view the source of this page http://www.islamkalvi.com/web/unicode_to_bamini.htm .. you will get one JavaScript function you can use that for convert Unicode font into Bamini encoding. Jeeva,..只需查看此页面的来源http://www.islamkalvi.com/web/unicode_to_bamini.htm ..您将获得一个JavaScript函数,您可以使用它将Unicode字体转换为Bamini编码。

To convert unicode to TSCII please refer to ThamiZha's TamilVisai . 要将unicode转换为TSCII,请参阅ThamiZha的TamilVisai They have released an InputMethod for Tamil and it's opensource. 他们已经发布了泰米尔语的InputMethod,它的开源。 Here is the link for their application source code . 这是他们的应用程序源代码的链接。 There is a class called UnicodeUtil which converts Unicode to TSCII on the fly. 有一个名为UnicodeUtil的类,它可以UnicodeUtil将Unicode转换为TSCII。

I have used the Bamini.ttf for tamil font. 我使用了Bamini.ttf作为tamil字体。 you will need to convert the tamil font to unicode by using bamini converter. 你需要使用bamini转换器将泰米尔语字体转换为unicode。 To get the source code for doing application in tamil. 获取在泰米尔语中执行应用程序的源代码。 Please visit the below website, 请访问以下网站,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM