How To Set Textview In Malayalam Font(an Indian Local Language) In Android 2.2
Solution 1:
Above code is correct and it should show Malayalam fonts. But there is a catch. if you phone doesn't support the font, it wont show Malayalam, but will show some boxes instead.
If you use any file browser and look into system/system/fonts - u will see all fonts supported by device.
If you want to add new fonts you can do that as well, but device has to be rooted for that. Many of the cheap phones just support few fonts, but costly phones have support for many fonts.
Solution 2:
At last I found the answer after a long search.. I converted Unicode fonts to Ascii,by replacing each and every Unicode character with Ascii. Here is the magic code
mytext.replaceAll("oldChar", "newChar");
use this code for each and every single character. :)
Solution 3:
Set custom font to TextView.
You have two ways, first see first way:
1. Add your font files to assets folder, if not exist assets folder create its.
2. Create CustomTypeface class, for examples:
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;
publicclassCustomTypeface {
privatestaticTypeface typefaseArialCondIt;
privatestaticTypeface typefaseArialBold;
privatestaticTypeface typefaseArialRegular;
publicCustomTypeface() {
}
publicCustomTypeface(Context context) {
AssetManager assets = context.getAssets();
CustomTypeface.typefaseArialCondIt = Typeface.createFromAsset(assets, "fonts/ArialCondIt.otf");
CustomTypeface.typefaseArialBold = Typeface.createFromAsset(assets, "fonts/ArialBold.otf");
CustomTypeface.typefaseArialRegular = Typeface.createFromAsset(assets, "fonts/ArialRegular.otf");
}
publicstaticTypefacegettypefaseArialCondIt() {
return typefaseArialCondIt;
}
publicstaticTypefacesettypefaseArialCondIt(Typeface typefaseArialCondIt) {
returnCustomTypeface.typefaseArialCondIt = typefaseArialCondIt;;
}
publicstaticTypefacegettypefaseArialBold() {
return typefaseArialBold;
}
publicstaticTypefacesettypefaseArialBold(Typeface typefaseArialBold) {
returnCustomTypeface.typefaseArialBold = typefaseArialBold;;
}
publicstaticTypefacegettypefaseArialRegular() {
return typefaseArialRegular;
}
publicstaticvoidsettypefaseArialRegular(Typeface typefaseArialRegular) {
CustomTypeface.typefaseArialRegular = typefaseArialRegular;
}
}
3. And set custom font to TextView:
TextViewyourTextView= (TextView) findViewById(R.id.textView1);
yourTextView.setTypeface(CustomTypeface.gettypefaseArialRegular);
Or second way, create custom TextView with your fonts:
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
publicclassArialTextViewextendsTextView {
publicArialTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
publicArialTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
publicArialTextView(Context context) {
super(context);
}
@OverridepublicvoidsetTypeface(Typeface tf, int style) {
if (style == Typeface.BOLD) {
setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/ArialBold.otf"));
} elseif (style == Typeface.NORMAL) {
setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/ArialRegular.otf"));
} elseif (style == Typeface.ITALIC) {
setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/ArialCondIt.otf"));
}
}
}
And in the layout xml you can create custom TextView, for example:
<com.your.package.ArialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="TextView with your custom font"/>
Solution 4:
I am not sure if this might work in your case but I worked with Punjabi font. What I did was not copied or entered the text into the string and then use the typeface. You certainly do use the typeface but in order for it to work properly you need to enter the Malayalam text in Transliteration i.e. as in the following example in Hindi as I don't know Malayalam.
PUl
Typefacecustom_typerface= Typeface.createFromAsset(getAssets(), "fonts/AnjaliNewLipi.ttf");
TextViewmytext= (TextView)findViewById(R.id.mytext);
mytext.setTypeface(custom_typerface);
mytext.setText("PUl"); //Assuming you know Hindi PUl in hindi is फूल
This will show the text in proper format with no issues however if you simply just enter
mytext.setText("फूल");
It is highly possible that it won't render the font properly. I hope this helps. :)
Post a Comment for "How To Set Textview In Malayalam Font(an Indian Local Language) In Android 2.2"