一键设置全部文本控件颜色

发表于 技术分享版块

创建一个名为setTextcolor.mjave的模块
在 setTextcolor 模块中粘贴以下代码

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.graphics.Color;

private void getAllViews(ViewGroup viewGroup,String color) {
    for (int i=0;i < viewGroup.getChildCount(); i++) {
        View view = viewGroup.getChildAt(i);
        if (view instanceof ViewGroup) {
            getAllViews((ViewGroup) view,color);
        } else {
            String str = view + "";
            //判断条件改成 view instanceof TextView 即匹配包含文字的控件
            if (str.contains("android.widget.TextView")) {
              if (view.getVisibility() == View.VISIBLE) {
                  //view.setBackgroundColor(Color.parseColor(color));
                  //设置文本背景
                  
                  TextView textView =(TextView)view;
                  textView.setTextColor(Color.parseColor(color));
                  //设置字体颜色
              }
            }
            
        }
    }
}
在需要设置的载入事件中使用以下代码调用

java(wind,activity,"android.app.Activity.getWindow")
java(group,wind,"android.view.Window.getDecorView")
call(null,"mjava","setTextcolor.getAllViews",group,"#ffffff")
//#ffffff替换为你要的颜色

本文章最后由 沐星河2024-11-10 01:40 编辑
评论列表 评论
发布评论

评论: 一键设置全部文本控件颜色

善语结善缘,恶言伤人心
 
已有0次打赏
(0) 分享
分享

请保存二维码或复制链接进行分享

取消