Skip to content Skip to sidebar Skip to footer

Android Tamil Font Between English Word

I am having a TextView that has a huge text in between i have a tamil word and i know how to embedd the tamil font in seperate textview .but i need the tamil word between english w

Solution 1:

Try setting this Akshar.ttf font to your TextView through setTypeface, it suuports both English and Tamil.


Here is the outcome:

enter image description here

Or, look for a similar font which supports both language.


your second solution is to use image for this small Tamil text portion using SpannableStringBuilder.


Code for setting custom font to TextView:

Assuming you have the Akshar.ttf font in fonts folder under assets folder:

Typefacetf= Typeface.createFromAsset(getAssets(), "fonts/Akshar.ttf");               
    TextViewtv= (TextView) findViewById(R.id.CustomFontText);
    tv.setTypeface(tf);
    tv.setText("Seasonal messages like welcome (நல்வரவு) is used in Kolam. Volunteering to draw kolam at temple is sometimes done when a devotee's");

Solution 2:

There is another solution if you want to support multiple fonts within a TextView but they are not supported within a single ttf:

Use the following code:(I'm using Bangla and Tamil font)

TextViewtxt= (TextView) findViewById(R.id.custom_fonts);  
        txt.setTextSize(30);
        Typefacefont= Typeface.createFromAsset(getAssets(), "Akshar.ttf");
        Typefacefont2= Typeface.createFromAsset(getAssets(), "bangla.ttf");   
        SpannableStringBuilderSS=newSpannableStringBuilder("আমারநல்வரவு");
        SS.setSpan (newCustomTypefaceSpan("", font2), 0, 4,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        SS.setSpan (newCustomTypefaceSpan("", font), 4, 11,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        txt.setText(SS);

The outcome is:

enter image description here


CustomTypefaceSpan Class:

package my.app;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;

publicclassCustomTypefaceSpanextendsTypefaceSpan {

privatefinal Typeface newType;

publicCustomTypefaceSpan(String family, Typeface type) {
    super(family);
    newType = type;
}

@OverridepublicvoidupdateDrawState(TextPaint ds) {
    applyCustomTypeFace(ds, newType);
}

@OverridepublicvoidupdateMeasureState(TextPaint paint) {
    applyCustomTypeFace(paint, newType);
}

privatestaticvoidapplyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typefaceold= paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    intfake= oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
}

Reference

Solution 3:

I had this problem in Android 4.0. I found that this is due to csc(Country Code). If it is a India then Tamil working correctly else not working. I can confirm this.

Solution 4:

Till ICS (4.0) there were no Tamil font available in Android Systems. Even then it had bugs and Google fixed it all with Jelly Bean (4.2).

Now if you wanna show Tamil in your application you need to use TAB, TAM, BAMINI or TSCII encodings.

I wrote a simple library that does the conversion for you dynamically. All you have to write is simple code as below.

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

I have written more on this topic in this answer. Please check it out too.

Post a Comment for "Android Tamil Font Between English Word"