Is there any way to use geomanist(custom) font in android lollipop.
But it works in all other version.
Here is my code
In MyApplication class
FontsOverride.setDefaultFont(this, "DEFAULT", "geomanist-lightnew.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "geomanist-lightnew.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "geomanist-lightnew.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "geomanist-lightnew.ttf");
public final 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();
}
}
}
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…