1.android studio选取Android列表,自动创建assets文件夹
转发:https://www.cnblogs.com/zxxiaoxia/p/7364366.html
2.创建MyApplication
package com.tayh.qrdemo;
import android.app.Application;
import android.graphics.Typeface;
import java.lang.reflect.Field;
public class MyApplication extends Application {
private static MyApplication application;
@Override
public void onCreate() {
super.onCreate();
application=this;
initType();
}
private void initType(){
Typeface typeface=Typeface.createFromAsset(getAssets(),"fonts/MicrosoftYaHei.ttf");
Field field = null;
try {
field = Typeface.class.getDeclaredField("MONOSPACE");
field.setAccessible(true);
field.set(null,typeface);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
3.添加style
<!-- theme. -->
<style name="AppTheme.Noactionbar" >
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:typeface">monospace</item>
</style>
4.修改manifest,主要添加application和theme
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.Noactionbar">