Monday, August 9, 2010

Use custom fonts in ANDROID

AIM : How to use Custom fonts programatically in android

Solution: 
Step 1) Download any font from internet
for example use this link to check some fonts( http://www.urbanfonts.com/free-fonts.htm )
and Save it in assets folder of the project .
Step 2) use the following lines
Creating a typeface object from assets folder

Typeface fontFace = Typeface.createFromAsset(getAssets(), "xtrusion.ttf");

Step 3) create a textview and apply the above typeface object to textview.

TextView someText = (TextView)findViewById(R.id.TextView01);
use any of the following methods to set typeface for textview.
someText.setTypeface(fontFace);    // only typeface

someText.setTypeface(fontFace, TextUtils.CAP_MODE_CHARACTERS);  // typeface with style properties.


By this way we can apply different fonts for our projects in android.

No comments:

Post a Comment

Android Developers Blog

Ram's shared items