Type Face Example

Description:
This example shows you can use your own typeface font and use into your application.

Algorithm:

1.) Create a new project by File-> New -> Android Project name it TypefaceExample.
2.) Write following code into res/layout.main.xml:

 

<!--?xml version="1.0" encoding="utf-8"?-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/CustomFontText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="Typeface Activity!!!! This is font Typeface example">

 

 

3.) Create a fonts folder into assets directory and put your font file i.e. “.otf” file there.

4.) Run for output.

Steps:

1.) Create a project named TypefaceExample and set the information as stated in the image.

Build Target: Android 2.1
Application Name: TypefaceExample
Package Name: com.org.typefaceexample
Activity Name: TypefacActivity
Min SDK Version: 7

2.) Open TypefaceActivity.java file and write following code there:

 

package com.org.typefaceexample;
import org.pack.R;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class TypefaceActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/File.otf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf);
}
}

 

 

3.) Compile and build the project.

Output

Leave a Comment:

4 comments
SAMKIT SHAH says January 14, 2012

gREAT EXAMPLE

Reply
Ramkumar says February 5, 2012

I tried this example by adding a Tamil Font with .ttf extension, it is not working.

Reply
Ali says February 7, 2012

Hi,
How can use my typeface in xml layout ?

Reply
akki says January 31, 2013

i didn’t get u what does type face means in android explain plzzzzzzzzzzzzzzzzzzzzzzzzzzz

Reply
Add Your Reply