黑马程序员技术交流社区

标题: 安卓使用自定义字体 [打印本页]

作者: 四季列车    时间: 2014-3-13 21:50
标题: 安卓使用自定义字体
安卓怎么使用自定义字体,安卓提供的字体满足不了需求:)
作者: 艮昕辶    时间: 2014-3-13 21:57
标题: 非本人原创 不过我自己看了一下好懂
  1. package arui.blog.csdn.net;   







  2. import android.app.Activity;     
  3. import android.graphics.Typeface;     
  4. import android.view.View;     
  5. import android.view.ViewGroup;     
  6. import android.widget.Button;     
  7. import android.widget.EditText;     
  8. import android.widget.TextView;     
  9. public class FontManager {   

  10.     public static void changeFonts(ViewGroup root, Activity act) {     
  11.        Typeface tf = Typeface.createFromAsset(act.getAssets(),     
  12.               "fonts/xxx.ttf");     
  13.        for (int i = 0; i < root.getChildCount(); i++) {     
  14.            View v = root.getChildAt(i);     
  15.            if (v instanceof TextView) {     
  16.               ((TextView) v).setTypeface(tf);     
  17.            } else if (v instanceof Button) {     
  18.               ((Button) v).setTypeface(tf);     
  19.            } else if (v instanceof EditText) {     
  20.               ((EditText) v).setTypeface(tf);     
  21.            } else if (v instanceof ViewGroup) {     
  22.               changeFonts((ViewGroup) v, act);     
  23.            }   







  24.        }     
  25.     }     }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2