Supporting desired fonts in your Android application


To begin with, you should have desired True Face Font file(*.ttf).

If you are having *.ttf  file then
1.        open your project in eclipse and copy  * .ttf  file into the  assets  folder, which will be in your project hierarchy.

2.        open  *.java file(which extends Activity) where you want to use the desired  font. Decalare necessary variables. In my example, I’m using a TextView and an EditText(In case of EditText, probably you should have a corresponding soft key board in your  desired font)
 Typeface font1;
 TextView txt1;
 EditText edtxt;

3.         In onCreate() method just write down this code.

/*here fonttype.ttf is the desired True Face Font file which was copied in assets folder.*/
font1 =Typeface.createFromAsset(getAssets(),"fonttype.ttf");
txt1 =(TextView) findViewById(R.id.user_id_txt);
edtx = (EditText) findViewById(R.id.editText);
//Set new type face to the views
txt1.setTypeface(font1);
edtx.setTypeface(font1);


That’s it.
Happy coding :-)

No comments:

Post a Comment