Change font of entire application in android

In android you can give your own customs fonts for all screens and widgets in the entire application. For achieving that you need to download the required fonts into your applications assets/fonts folder. So the first thing you want to do after creating the project is to create an assets folder.

  1. click on file->new->folder->Assets Folder
  2. A popup will come, In that click on finish button without checking “change folder location”.
  3. In assets folder will get created, Again right -click on it and create another directory inside assets and name it as “fonts”
  4. Put your custom font inside this folder
  5. Now create a file in java/your package/

Here is the code for

public class TypefaceUtil {

public static void overrideFont(Context context, String defaultFontNameToOverride, String customFontFileNameInAssets) {

final Typeface customFontTypeface = Typeface.createFromAsset(context.getAssets(), customFontFileNameInAssets);

Map<String, Typeface> newMap = new HashMap<String, Typeface>();
newMap.put("serif", customFontTypeface);
try {
final Field staticField = Typeface.class
staticField.set(null, newMap);
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
} else {
try {
final Field defaultFontTypefaceField = Typeface.class.getDeclaredField(defaultFontNameToOverride);
defaultFontTypefaceField.set(null, customFontTypeface);
} catch (Exception e) {
Log.e(TypefaceUtil.class.getSimpleName(), "Can not set custom font " + customFontFileNameInAssets + " instead of " + defaultFontNameToOverride);

6. Create a file in java/your package/, this class will extend as Application

Here is the code for

public class CustomFontApp extends Application {
public void onCreate() {

TypefaceUtil.overrideFont(getApplicationContext(), "SERIF", "fonts/OpenSans-SemiboldItalic.ttf");


7. Next step is to register our custom Application to AndroidManifest.xml file. So your the application tag in manifest will be :


8.Finally add the following line to your styles.xml to the style which you are reffering in

<item name="android:typeface">serif</item>

Above you saw to how give custom font to the entire android application.

Suppose if you just want to change only a single strings font , then you need to specifically setTypeface to that widget.

First you need to define your custom font in your activity by

Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-SemiboldItalic.ttf");

now use the below code for your textview(can be button or any other view contains text)

your_textview.setTypeface(custom_font );



About the author

Hi guys, i am the author of codesfor. I am a B.Tech graduate currently working as an App developer. Apart from job i am a blogger and a freelancer.


  1. Sathish Kumar January 16, 2019 Reply

Add a Comment

Your email address will not be published. Required fields are marked *