安卓中批量修改控件字体和样式

来源:互联网 发布:大数据教程 pdf 编辑:程序博客网 时间:2024/05/23 01:47

先要导入一些字体样式文件到assets资产目录下

安卓中批量修改控件字体和样式

java代码如下:


 protected void changeFont(ViewGroup root) {
  Typeface tf =Typeface.createFromAsset(getAssets(),
    "typeface/fangzhengjingleijianti.TTF");
  for (int i = 0; i <root.getChildCount(); i++) {
   View v =root.getChildAt(i);
   if (vinstanceof TextView) {
    ((TextView)v).setTypeface(tf);
//    ((TextView)v).setTextSize(15);
//    ((TextView)v).setTextColor(Color.GRAY);
   } else if (vinstanceof Button) {
    ((Button)v).setTypeface(tf);
//    ((Button)v).setTextSize(15);
//    ((Button)v).setTextColor(Color.GRAY);
   } else if (vinstanceof EditText) {
    ((EditText)v).setTypeface(tf);
//    ((EditText)v).setTextSize(15);
//    ((EditText)v).setTextColor(Color.GRAY);
   } else if (vinstanceof ViewGroup) {
    changeFont((ViewGroup)v);
   }
  }

 }

 

 

以上做法能达到批量修改的效果, 但是程序运行比较卡, 我还没找到合适的方法, 如果有大神知道请告知.....

0 0
原创粉丝点击