Skip to content

Instantly share code, notes, and snippets.

@m7mdra
Created March 22, 2017 16:16
Show Gist options
  • Save m7mdra/0d2c2571f80e5906c7ee5b763430cb4c to your computer and use it in GitHub Desktop.
Save m7mdra/0d2c2571f80e5906c7ee5b763430cb4c to your computer and use it in GitHub Desktop.
package m7mdra.io.services.util;
import android.content.Context;
import android.graphics.Typeface;
import java.lang.reflect.Field;
public class TypefaceUtil {
public static void overrideFont(Context context) {
try {
final Typeface customFontTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/Cairo-Regular.ttf");
final Field defaultFontTypefaceField = Typeface.class.getDeclaredField("SERIF");
defaultFontTypefaceField.setAccessible(true);
defaultFontTypefaceField.set(null, customFontTypeface);
} catch (Exception e) {
PLogger.p("Can not set custom font " + "fonts/Cairo-Regular.ttf" + " instead of "+ "SERIF");
PLogger.p("overrideFont: "+e.toString() );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment