Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###### java code for FontOverride
- package com.example.shikhadwivedi.homeautomation;
- /**
- * Created by shikha on 9/7/18.
- */
- import android.content.Context;
- import android.graphics.Typeface;
- import java.lang.reflect.Field;
- 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();
- }
- }
- }
Add Comment
Please, Sign In to add comment