使用的是反射机制,通过搜索MONOSPACE的字体类型,把其字体设置成我们想要的字体
在自定义的Application里面声明全局字体。在assets中建立fonts文件夹,里面存放自定义的字体。
在style.xml声明全局的字体类型
public final class App extends MApplication {
public static Typeface TypeFaceYaHei;
@Override
public void onCreate () {
super .onCreate();
TypeFaceYaHei = Typeface.createFromAsset(getAssets(), "fonts/PingHeiText.ttf" );
try
{
Field field = Typeface.class.getDeclaredField("MONOSPACE" );
field.setAccessible(true );
field.set(null , TypeFaceYaHei);
}
catch (NoSuchFieldException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
}
}
全局的数据类型
<style name ="theme_fullScreen" parent="AppBaseTheme" >
<!
<item name ="android:windowNoTitle" >true </item >
<!
<item name ="android:typeface" >monospace</item >
</style>
设置Application的主题
<application
android:name="com.code.space.app.App"
android:allowBackup="true"
android:icon="@drawable /ic_launcher"
android:label="@string /app_name"
android:theme="@style /theme_fullScreen" >