rhino
// 这里是空的
nodejs
"nodejs ui-thread";
"ui"和"ui-thread"是有区别的:
let w = floaty.rawWindow(
<vertical>
<button id="changeColor">改变颜色</button>
<text id="content">Hello, World!</text>
</vertical>
);
w.changeColor.click(() => {
w.content.attr("bg", colors.toString(colors.RED));
});
setInterval(() => {}, 1000);
ui.post(function () {
let dw = device.width;
let dh = device.height;
let ww = w.width;
let wh = w.height;
let x = (dw - ww) / 2;
let y = (dh - wh) / 2;
w.setPosition(x, y);
}, 300);
rhino
floaty.rawWindow()
nodejs
const { createWindow } = require("floating_window");
let window = createWindow();
接着在悬浮窗里输入具体的xml文件
rhino
let w = floaty.rawWindow(
<vertical>
<button id="changeColor">改变颜色</button>
<text id="content">Hello, World!</text>
</vertical>
);
nodejs
window.setViewFromXmlFile('./fw.xml');
两者的xml都可以是独立的xml文件, fw.xml的文件内容是一样的
<vertical>
<button id="changeColor">
改变颜色
</button>
<text id="content">
Hello, World!
</text>
</vertical>
nodejs大部分方法都是异步的, 因此大部分方法都要await,
await 要在async里面, 因此我们创建一个函数, async一下
async function main() {
let window = createWindow();
await window.setViewFromXmlFile("./fw.xml");
}
main();
rhino
w.changeColor
nodejs
let view = window.view.findView("changeColor");
rhino
w.changeColor.click(() => {
......
});
nodejs
let callback=function (){
......
}
view.on("click", callback);
rhino
setInterval(() => {}, 1000);
nodejs
$autojs.keepRunning();
rhino
ui.post(function () {
}, 300);
nodejs
const { delay } = require('lang');
await delay(500);
rhino
let dw = device.width;
nodejs
const { device } = require("device");
let dw = device.screenWidth;
rhino
let ww = w.width;
nodejs
let ww = window.size.width
正常的话就是上面酱紫, 但是现在这个nodej的size有bug, 因此我们换种方法获取宽度
let ww = window.view.getWidth()
rhino
w.setPosition(x, y);
nodejs
await window.setPosition(x, y);
rhino
w.content.attr("bg", colors.toString(colors.RED));
nodejs
let view = window.view.findView("content");
view.attr("bg", "#ff0000");
"nodejs ui-thread";
const { createWindow } = require("floating_window");
const { delay } = require("lang");
const { device } = require("device");
const color = require("color");
async function main() {
let window = createWindow();
await window.setViewFromXmlFile("./fw.xml");
let view = window.view.findView("changeColor");
let callback = function () {
let view = window.view.findView("content");
view.attr("bg", "#ff0000");
};
view.on("click", callback);
await window.show();
await delay(200);
let dw = device.screenWidth;
console.log(dw);
let dh = device.screenHeight;
let ww = window.view.getWidth();
let wh = window.view.getHeight();
let x = (dw - ww) / 2;
let y = (dh - wh) / 2;
await window.setPosition(x, y);
}
main();
$autojs.keepRunning();
设备: 小米11pro
Android版本: 12
Autojs版本: 9.2.13
思路是最重要的, 其他的百度, bing, stackoverflow, github, 安卓文档, autojs文档, 最后才是群里问问 --- 牙叔教程
部分内容来自网络 本教程仅用于学习, 禁止用于其他用途