android 使用第三方字体(全局)
2018-03-16 13:51
459 查看
使用的是反射机制,通过搜索MONOSPACE的字体类型,把其字体设置成我们想要的字体
在自定义的Application里面声明全局字体。在assets中建立fonts文件夹,里面存放自定义的字体。
在style.xml声明全局的字体类型
全局的数据类型
设置Application的主题
单个控件引用外来字体
在自定义的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> <!--<span style="white-space:pre"></span>--> <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" >
单个控件引用外来字体
//设置了外来的字体 // Typeface face = Typeface.createFromAsset (getAssets() , "fonts/SourceHanSansCN-ExtraLight.TTF" ); // fabu_des.setTypeface (face);
相关文章推荐
- Android 全局使用第三方字体
- Android 全局使用第三方字体
- Android应用使用第三方字体
- Android应用使用第三方字体
- Android全局使用自定义字体
- Android使用第三方字体
- 快速使用反射更换Android全局字体
- android 应用使用第三方字体 (瘦身方案)
- Android 使用Font XML替换App全局字体样式
- Android字体及使用第三方字体库
- android 使用第三方字体库
- Android使用第三方或者自制字体库(Typespace)
- android 改变全局字体样式(第三方字体包)
- Android之应用设置全局字体(第三方字体)
- Objective-C Runtime使用之全局字体替换为第三方字体(iOS)
- Android应用开发使用第三方字体
- Android TextView 中如何使用第三方字体
- Android 全局替换第三方字库(自定义字体)
- Android中使用自定义的字体
- Android使用Application代替全局变量