Saturday, 24 November 2012

Android Development – Customize Android Fonts

First Create New Android Project and after that add "DroidSansFallback.ttf" file into assets folder.

After that put below code into activity_main.xml file and MainActivity.java file

activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Dipak Keshariya"
        android:id="@+id/TextView1" />

</LinearLayout>


MainActivity.java

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     
        // text view label
        TextView mTextView1 = (TextView) findViewById(R.id.TextView1);

        // Loading Font Face
        Typeface tf = Typeface.createFromAsset(getAssets(), "DroidSansFallback.ttf");

        // Applying font
        mTextView1.setTypeface(tf);
    }
}

Download Full Source Code from below link.

Customize Android Fonts

Don’t forget to provide feedback or follow this blog, if you find this blog is useful.

No comments:

Post a Comment