Android中的泰米尔语字体 [英] Tamil fonts in Android

查看:350
本文介绍了Android中的泰米尔语字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android版本 2.3.3 中开发了一个泰米尔语新闻应用程序。但是,泰米尔语字体只能在Android 4.0及以上版本中正确开发。我想在Android手机的所有版本中显示它们。

我试图解决一些泰米尔字体的问题,比如 bamini mylai

首先,你必须明白,在ICS(4.0)之前,在Android OS(除了少数三星和东芝手机)上没有泰米尔语言支持。即使这样,它也会有bug,而且Jelly Bean(4.2)也提供了全面的支持。

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

1。手动方式



这个解决方案有一个解决方法。您只需下载Bamini字体并将其放置在资产文件夹中即可。使用字体Bamini创建TypeFace,并将其设置为TextView。



pre $>字体font1 =字体/ Bamini.ttf);
customText1.setTypeface(font1);

现在使用转换器将Unicode字体转换成Bamini 编码。而不是Unicode文本将转换后的Bamini编码脚本提供给 setText 方法。

2。使用库



如果您讨厌所有这些手动编码转换,请查看这个正如我在上面所说的,如果你想在运行应用程序时动态地改变编码,那么考虑使用我为Android编写的库。这个库将帮助您将Unicode字符串转换为Bamini,TSCII,TAB,TAM和Anjal。

设置起来很简单。所有你需要做的只是将库导入到你的Android项目,并调用库如下。

  //初始化字体(假设位于资产/字体文件夹中的TSCII,Bamini,Anjal,TAB或TAM字体)
Typeface tf = Typeface.createFromAsset(getAssets(),fonts / mylai.ttf);
//初始化TextView
TextView tv =(TextView)findViewById(R.id.textView1);
//设置字体
tv.setTypeface(tf);
//魔术在这里发生;)编码转换
String TSCIIString = TamilUtil.convertToTamil(TamilUtil.TSCII,வணக்கம்அன்ரொயிட்);
//将新字符串设置为TextView
tv.setText(TSCIIString);

有一个示例应用程序与库一起提供。查看应用程序如何利用库将Unicode字符串转换为Bamini,TAB,TAM,TSCII和Anjal。



当你使用库时,你会得到类似的东西。 /raw.github.com/mayooresan/Android-TamilUtil/master/ScreenShot.pngalt =屏幕截图泰米尔语Unicode转换器Utilltitle =Android泰米尔语>



您需要使用Android中提供的 TypeFace 类。您可以使用Bamini或TSCII编码(Mylai是TSCII字体)。



免责声明:我写了这个库。

3。对于WebView



如果您正在开发使用包装在WebView中的html和CSS,请查看这个应用程序的来源。你将不得不使用CSS3的 fontface 功能。

首先,你需要将style声明为

  @ font-face {
font-family:MyCustomFont;
src:url(Bamini.ttf)/ * CSS3浏览器的TTF文件* /
}

然后,您必须在您的代码中使用 MyCustomFont 。例如,如果你想把它设置到整个身体(在这种情况下更容易)

$ p $ body {
font-family:MyCustomFont,Verdana,Arial,sans-serif;
font-size:medium;
color:black
}

值得。希望在Play商店中看到更多泰米尔应用。


I developed a Tamil news application in android version 2.3.3. However, Tamil fonts have only been properly developed in android versions 4.0 and beyond. I want to display them in all versions of android mobile.

I tried to solve the problem with some Tamil fonts, such as bamini and mylai, but they only worked in higher android versions.

解决方案

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). Even then it had bugs and full support is provided with Jelly Bean (4.2).

You will only see boxes if you use Unicode Tamil font in your app. Reason is there are no Tamil fonts in the system.

1. Manual way of doing

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. And create TypeFace with the font Bamini and set it to the TextView.

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

Now use a converter to convert Unicode font into Bamini encoding. instead of the Unicode text provide the converted Bamini encoded script into the setText method.

2. Using the Library

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. This library will help you to convert Unicode String to Bamini, TSCII, TAB, TAM and 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.

// 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.

You would get something like this when you use the library.

You need to make use of the TypeFace class available in Android. You can use either Bamini or TSCII encoding (Mylai is a TSCII font).

Disclaimer : I wrote this library.

3. For WebView

If you are developing using html and CSS wraped inside a WebView then take a look at this application's source. You gonna have to make use of fontface feature of CSS3.

First you need to have style declared as this

@font-face {
 font-family: MyCustomFont;
 src: url("Bamini.ttf") /* TTF file for CSS3 browsers */
}

Then you gotta use the MyCustomFont in your tags. For example if you wanna set it to the whole body (which is much easier in this case)

body {
 font-family: MyCustomFont, Verdana, Arial, sans-serif;
 font-size: medium;
 color: black
}

Hope this would give you the heads up you deserve. Hope to see more Tamil apps in Play Store.

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

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