新建MyApplication,在AndroidMainfest中使用
1)下载字体,放在在项目的main目录下新建assets文件夹——新建fonts,如图
2)Myapplication中,指定字体
1: StringfontPath ="fonts/FZSTK.TTF";
2: public void replaceSystemDefaultFont(Context context, String fontPath) {
replaceTypefaceField("MONOSPACE", Typeface.createFromAsset(context.getAssets(), fontPath));
}
3: private void replaceTypefaceField(String fieldName, Object value) {
try {
Field defaultField = Typeface.class.getDeclaredField(fieldName);
defaultField.setAccessible(true);
defaultField.set(null, value);
}catch (NoSuchFieldException e) {
e.printStackTrace();
}catch (IllegalAccessException e) {
e.printStackTrace();
}
}
4:调用方法 replaceSystemDefaultFont(getApplicationContext(), fontPath);