Android: how to use Tamil fonts
This is my Tamil HTML Unicode string
முதல்பக்கக்திகள்
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("முதல் பக்க செய்திகள்");
Is this possible in Android?
resolvent:
First, you must understand that there is no Tamil language support in the Android operating system (except for a few Samsung and Se phones) until ICs (4.0). Even so, it has bugs, and Jerry bean (4.2) provides comprehensive support
If you use Unicode Tamil font in your application, you will only see the box. The reason is that there is no Tamil font in the system
This solution has a solution. All you have to do is download the bamini font and put it in your resource folder. Use the font bamini to create a typeface and set it as textview
Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/Bamini.ttf");
customText1.setTypeface(font1);
Now use the converter to convert Unicode font into bamini encoding. Instead of Unicode text, provide the converted bamini encoding script to the settext method
If you hate all these manual transcoding, check out this library
As I said above, if you want to dynamically change the encoding when running the application, consider using the library, which I wrote for Android. The library will help you convert Unicode strings to bamini, tscii, tab, TAM and anjal
The setup is simple. You just import the library into the Android project and call the library, as shown 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);
The library provides sample app. See how the application uses the library to convert Unicode strings to bamini, tab, Tam, tscii and anjal
Please be sure to read my comprehensive answers on how to solve Tamil on Android native apps and webviews here in this answer