Using Custom Fonts in Android
by Sasikumar[ Edit ] 2014-02-17 10:07:10
To use custom fonts in android app:
1. Download the .ttf file (Ex. myNewFont.ttf) of the required font and place in "assets/fonts" folder. Create "fonts" folder if it doent exists.
2. To set the font to TextView use following code
TextView email = (TextView) findViewById(R.id.email);
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(),"fonts/myNewFont.ttf");
email.setTypeface(typeface);
Similarly we can set custom font to any element.
3. To set custom font in webview use the following method
<style type="text/css">
@font-face {
font-family:"myNewFont1";
src:url('file:///android_asset/fonts/myNewFont1.ttf');
}
@font-face {
font-family:"myNewFont2";
src:url('file:///android_asset/fonts/myNewFont2.ttf');
}
body { font-family:'myNewFont1'; }
h1 { font-family:'myNewFont2'; }
p { font-family:'myNewFont1'; }
</style>