Created
March 22, 2017 16:16
-
-
Save m7mdra/0d2c2571f80e5906c7ee5b763430cb4c 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 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