Android Custom Font Example Tutorial.
1.
Create a new project.
2.
Create a folder called assets and place all your fonts in it.
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" android:gravity="center"> <TextView android:id="@+id/ghost" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="30dp" android:text="MIHIR" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/etd" android:textSize="30dp" android:gravity="center" android:layout_marginTop="50dip"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp" android:id="@+id/btn" android:text="Hello"/> </LinearLayout>
MainActivity.java
package com.cutomfontexample; import android.app.Activity; import android.graphics.Typeface; import android.os.Bundle; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String fontPath = "CHILLER.TTF"; // Loading Font Face Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); // text view label TextView txtGhost = (TextView) findViewById(R.id.ghost); // edittext view EditText etd = (EditText)findViewById(R.id.etd); // button view Button btn = (Button)findViewById(R.id.btn); // Applying font txtGhost.setTypeface(tf); etd.setTypeface(tf); btn.setTypeface(tf); } }