Thursday, 2 April 2015

Add fonts to android application

Here I am going to explain how to add an external font style to android application programmatically.

Step 1).Download the font type from here.
Step 2).Create a folder "fonts" inside the "assests" folder.
Step 3).Import The jar file into the folder "fonts".




Step 4).Open the fonts.xml file and create Textview.



<?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"
    android:background="#000000" >
    <TextView
        android:id="@+id/newfont"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textSize="50dip"
        android:gravity="center"
        android:textColor="#ffffff"
        android:layout_marginTop="60dip"
        android:text="NewFont" />
</LinearLayout>

Step 4).Fonts.java


package com.example.androidhive;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class Fonts extends Activity 
{
TextView newFont;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
  String Path= "";//Type your path
   newFont=(TextView)findViewById(R.id.newfont);
      Typeface T = Typeface.createFromAsset(getAssets(), Path);
   newFont.setTypeface(T);
       
       
    }
}

Happy Coding :)....