1.Android 系统提供字体


android:typeface="serif"



android:textStyle="bold"



android:fontFamily="sans-serif"



2.Android 替换TextView字体

Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Avenir Next.ttc");new TextView(this).setTypeface(typeface);



3.Android 替换全局字体


(1).设置主题中默认使用字体

name="android:typeface">serif

(2).在Application 中初始化如下方法


   使用反射机制获取第一步中设置默认字体,并使用自定义字体Exo2-Black.ttf 替换 

private void initTypeface(){    try {        Field field = Typeface.class.getDeclaredField("SERIF");        field.setAccessible(true);        field.set(null, Typeface.createFromAsset(getAssets(), "fonts/Exo2-Black.ttf"));    } catch (NoSuchFieldException e) {        e.printStackTrace();    } catch (IllegalAccessException e) {        e.printStackTrace();    }}

另外,还有一种方法可实现字体替换:

获取activity的整个view,通过view.getChild 循环递归 给获取到的 view 设置字体,因性能问题不建议使用

更多相关文章

  1. android 字体总结
  2. Android基本控件常用属性及方法
  3. android字体小结
  4. Android如何让TextView子元素随着父元素的背景变化而改变字体颜
  5. Android学习笔记(2)---android字体风格设置
  6. Android中一个Activity多个intent-filter的调用方法

随机推荐

  1. Android(安卓)API开发之OpenGL开发之Andr
  2. 从jdk1.7.0获取MD5认证指纹方法
  3. Android(安卓)笔记
  4. Cordova更改Gradle版本
  5. 2011.09.01(3)——— android service star
  6. Android(安卓)判断SIM卡属于哪个移动运营
  7. Android(安卓)开机自启动 App
  8. 2010.12.29(2)——— android GridView
  9. android用户界面之TabHost教程实例汇总
  10. ReactNative: Android与iOS平台兼容处理