Friday, 29 November 2013

External Font Across the Android Application

Hello Friends, Today i am going to share Custom Font style of text view for whole application.

Sometimes in Android app we may need to maintain same font across application. At point of time previews post is not sufficient.

Here below Example shows how to use External font across the application.

Here First I have downloaded ".ttf” file from google. Created a new folder “font” in assets folder and paste your recently downloaded font file.

we can do that by just extending your class from android TextView.

Below code is to my customized TextView class(

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

public class CustomFontTextView extends TextView
public CustomFontTextView(Context context, AttributeSet attrs, int defStyle)
super(context, attrs, defStyle);

public CustomFontTextView(Context context, AttributeSet attrs)
// call the constructor which has the complete definition
this(context, attrs, 0);

public CustomFontTextView(Context context)

public void setFont()
String ttf_fontPath = "fonts/TIMES_SQ.TTF";
Typeface font = Typeface.createFromAsset(getContext().getAssets(),ttf_fontPath);
In our Layout insted of declare <TextView/> tag we just specify <com.hb.CustomFontTextView/>
in any were in our application.
        android:text="Hello Android"
        android:textSize="45dp" />
Then external font will be applied to Text.
I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)