Skip to content

Instantly share code, notes, and snippets.

@vamsitallapudi
Created August 28, 2019 14:49
Show Gist options
  • Save vamsitallapudi/37c941b75acb06bed930c5eeebf47d7c to your computer and use it in GitHub Desktop.
Save vamsitallapudi/37c941b75acb06bed930c5eeebf47d7c to your computer and use it in GitHub Desktop.
package com.coderefer.firebasedatabaseexample.util;
import android.content.Context;
import android.graphics.Typeface;
import java.lang.reflect.Field;
/**
* Created by vamsi on 06-05-2017 for Android custom font article
*/
public class FontsOverride {
public static void setDefaultFont(Context context,
String staticTypefaceFieldName, String fontAssetName) {
final Typeface regular = Typeface.createFromAsset(context.getAssets(),
fontAssetName);
replaceFont(staticTypefaceFieldName, regular);
}
protected static void replaceFont(String staticTypefaceFieldName,
final Typeface newTypeface) {
try {
final Field staticField = Typeface.class
.getDeclaredField(staticTypefaceFieldName);
staticField.setAccessible(true);
staticField.set(null, newTypeface);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment