怎么隐藏在前台运行的脚本页面

已存档
hu9hjwhtol · 15 天前

回答

Hamibot AI
1
· 15 天前

要隐藏前台运行的脚本页面元素(如悬浮窗或控制台),需根据具体场景使用以下方法:

一、隐藏悬浮窗

若使用 floaty.window() 创建了悬浮窗,可通过 close() 方法关闭:

// 创建悬浮窗
var w = floaty.window(
    <frame gravity="center" bg="#FF0000">
        <text>悬浮文字</text>
    </frame>
);

// 5秒后关闭悬浮窗
setTimeout(function() {
    w.close();
}, 5000);

二、隐藏控制台输入框和按钮

若通过 console.show() 显示了控制台,需通过反射隐藏输入框:

// 显示控制台
console.show();

// 隐藏输入框和确定按钮
ui.run(function() {
    let mConsoleViewField = runtime.console.getClass().getDeclaredField('mConsoleView');
    mConsoleViewField.setAccessible(true);
    let refConsoleView = mConsoleViewField.get(runtime.console);
    let mConsoleView = refConsoleView.get();
    mConsoleView.findViewById(com.stardust.autojs.R.id.input_container).visibility = android.view.View.GONE;
});

log('控制台已隐藏输入区域');

三、替代方案:自定义悬浮窗

若需完全自定义悬浮窗,可使用以下代码:

let fw = floaty.rawWindow(
    <vertical w="200" h="200" bg="#80333333">
        <text bg="#000000" textColor="#ffffff">自定义悬浮窗</text>
        <com.stardust.autojs.core.console.ConsoleView id="console"/>
    </vertical>
);

// 绑定控制台输出
fw.console.setConsole(runtime.console);

// 隐藏原始输入组件
ui.run(function() {
    fw.console.findViewById(com.stardust.autojs.R.id.input_container).visibility = android.view.View.GONE;
});

log('测试输出到自定义悬浮窗');

以上方法均基于 Hamibot API 实现,无需额外权限。注意避免使用 箭头函数,确保兼容 Rhino 1.7.15 引擎。

ℹ️ 本回答由 AI 生成,内容仅供参考