hamibot.env 这个表单能显示在手机ui界面吗
8:40:25.190/E: Wrapped android.view.InflateException: org.xml.sax.SAXParseException: Attr.value missing f. select_runtype (position:START_TAG <com.stardust.autojs.core.ui.widget.JsTextView android:text='{   ' select_runtype='http://schemas.android.com/apk/res/android'>@10:18 in java.io.InputStreamReader@d26a901)  (file:///android_asset/modules/ui.js#18)
Wrapped android.view.InflateException: org.xml.sax.SAXParseException: Attr.value missing f. select_runtype (position:START_TAG <com.stardust.autojs.core.ui.widget.JsTextView android:text='{   ' select_runtype='http://schemas.android.com/apk/res/android'>@10:18 in java.io.InputStreamReader@d26a901)
at file:///android_asset/modules/ui.js:18:0
at 685a56da94281869989c8c49.js:7:0   用上面给出的方案会报错
回答
hamibot.env 是用于脚本配置的表单数据,它本身不会直接显示在手机 UI 界面。但你可以通过 UI 模块将这些配置内容展示在手机界面上。例如:
'ui';
// 文档地址 https://docs.hamibot.com/
ui.layout(
    <vertical>
        <text text="配置内容:" />
        <text text={JSON.stringify(hamibot.env, null, 2)} />
    </vertical>
);
// 保持界面显示
setInterval(() => {}, 1000);
如果你想让用户通过 UI 界面修改配置,需要自己编写 UI 表单控件(如输入框、选择框等),并在保存时将数据写入 hamibot.env。
记得 UI 脚本必须在首行添加 'ui'; 声明。
补充回答 1
这个错误是因为 XML 布局中存在属性值缺失的问题。根据错误信息,select_runtype 属性缺少值。我们可以这样修正:
'ui';
// 文档地址 https://docs.hamibot.com/
ui.layout(
    <vertical>
        <text text="配置内容:" />
        <text text={JSON.stringify(hamibot.env)} />
    </vertical>
);
// 保持界面显示
setInterval(() => {}, 1000);
主要修改点:
- 移除了 JSON.stringify的格式化参数(原先的null, 2)
- 确保所有 XML 属性都有正确的值
如果仍然有问题,可以尝试:
- 检查 hamibot.env是否包含循环引用的对象
- 将输出内容先保存在变量中再显示
'ui';
// 文档地址 https://docs.hamibot.com/
var envText = JSON.stringify(hamibot.env);
ui.layout(
    <vertical>
        <text text="配置内容:" />
        <text text={envText} />
    </vertical>
);
setInterval(() => {}, 1000);