Created
August 28, 2019 14:49
-
-
Save vamsitallapudi/37c941b75acb06bed930c5eeebf47d7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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