使用场景
自定义控制台
效果展示
autojs版本号
原理
- 获取控制台实体
- 遍历控制台窗口
- 设置背景为红色
代码讲解
- 获取控制台实体
let mConsoleView = getConsoleWindow(); function getConsoleWindow() { var mConsole = runtime.console; let field = mConsole.class.superclass.getDeclaredField("mConsoleFloaty"); field.setAccessible(true); mConsoleFloaty = field.get(mConsole); mConsoleView = mConsoleFloaty.getExpandedView(); return mConsoleView; }
- 遍历控制台窗口
let r = filterView(mConsoleView); function filterView(view, arr) { arr = arr || []; if (view instanceof android.view.ViewGroup) { arr.push(view); let childCount = view.childCount; for (var i = 0; i < childCount; i++) { let chileView = view.getChildAt(i); filterView(chileView, arr); } } else { arr.push(view); } return arr; }
- 设置背景为红色
let num = 15; ui.run(function () { r[num].setBackgroundColor(colors.parseColor("#ff0000")); });
- 隐藏输入框和按钮
let parent = mConsoleView.parent; var inputView = parent.findViewById(context.getResources().getIdentifier("input", "id", context.getPackageName())); var buttonView = parent.findViewById(context.getResources().getIdentifier("submit", "id", context.getPackageName())); ui.run(function () { inputView.setVisibility(8); buttonView.setVisibility(8); });
- 设置字体大小和颜色
let num = 10; ui.run(function () { let recycleview = r[num]; let adapter = recycleview.getAdapter(); function createAdapter() { let result = new JavaAdapter( Packages[adapter.getClass().getName()], { onBindViewHolder: function (vh, i) { adapter.onBindViewHolder(vh, i); vh.textView.setTextSize(30); vh.textView.setTextColor(colors.parseColor("#2ed573")); }, }, recycleview.parent.parent, null ); return result; } let newAdapter = createAdapter(); recycleview.setAdapter(newAdapter); });
- 打印日志
console.log("AutoJsPro教程 \n牙叔");