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(安卓)总结1
  2. 在Android(安卓)Studio中使用Android(安卓)Tests(Junit)
  3. Android(安卓)系统级应用守护进程
  4. shape 的使用xml
  5. Android(安卓)RatingBar自定义替换系统图片
  6. 《疯狂Android讲义》第二版目录
  7. android webview开发html5
  8. Android中的Context详解
  9. Property Animation属性动画,还用补间动画你就out了

随机推荐

  1. Android设计模式学习之Builder模式
  2. Android全局代理软件ProxyDroid和TransPr
  3. 【Android(安卓)UI】 Shape详解
  4. Android(安卓)热修复一(热修复流程原理)
  5. Android(安卓)DOM解析xml
  6. android 制作.9.png图片
  7. Android(安卓)VS iPad
  8. 谷歌评选出第二届Android开发者竞赛获胜
  9. Android(安卓)spinner取值
  10. android app的启动优化方法