Autojs模块:UI界面

脚本如何对接UI界面

哔哩哔哩:https://www.bilibili.com/video/BV1rCfiYxEKW/

示例代码


1、按钮控件


  1. "ui";
  2. ui.layout(
  3. <vertical padding="16">
  4. <button text="普通按钮" w="auto"/>
  5. <button text="带颜色按钮" style="Widget.AppCompat.Button.Colored" w="auto"/>
  6. <button text="无边框按钮" style="Widget.AppCompat.Button.Borderless" w="auto"/>
  7. <button text="无边框有颜色按钮" style="Widget.AppCompat.Button.Borderless.Colored" w="auto"/>
  8. <button text="长长的按钮" w="*"/>
  9. <button id="click_me" text="点我" w="auto"/>
  10. </vertical>
  11. );
  12. ui.click_me.on("click", ()=>{
  13. toast("我被点啦");
  14. });
  15. ui.click_me.on("long_click", ()=>{
  16. toast("我被长按啦");
  17. });

2、表格控件(一)

3、表格控件(二)

4、表格控件(三)

5、表格控件(四)

  1. "ui";
  2. ui.layout(
  3. <vertical>
  4. <linear>
  5. <input id="input" layout_weight="1" textColor="black" textSize="16sp" marginLeft="16"/>
  6. <button id="search" text="搜索" style="Widget.AppCompat.Button.Borderless.Colored"/>
  7. <button id="reset" text="重置" style="Widget.AppCompat.Button.Borderless.Colored"/>
  8. </linear>
  9. <grid id="icons" spanCount="4" h="*">
  10. <img src="@drawable/{{this}}" h="80" margin="12" bg="?selectableItemBackgroundBorderless"/>
  11. </grid>
  12. </vertical>
  13. );
  14. //部分内置图标名称
  15. var icons = ['ic_speaker_phone_black_48dp', 'ic_stay_current_landscape_black_48dp', 'ic_stay_current_portrait_black_48dp', 'ic_stay_primary_landscape_black_48dp'];
  16. ui.icons.setDataSource(icons);
  17. ui.icons.on("item_click", function(icon){
  18. var d = "@drawable/" + icon;
  19. setClip(d);
  20. toast(d + "已复制到剪贴板");
  21. });
  22. ui.search.on("click", function(){
  23. var text = ui.input.text();
  24. if(text.length == 0){
  25. return;
  26. }
  27. search(text);
  28. });
  29. ui.reset.on("click", function(){
  30. ui.icons.setDataSource(icons);
  31. });
  32. function search(keywords){
  33. var result = [];
  34. for(var i = 0; i < icons.length; i++){
  35. var icon = icons[i];
  36. if(icon.indexOf(keywords) >= 0){
  37. result.push(icon);
  38. }
  39. }
  40. ui.icons.setDataSource(result);
  41. }

6、复选框单选框控件

  1. "ui";
  2. ui.layout(
  3. <vertical padding="16">
  4. <checkbox id="cb1" text="复选框"/>
  5. <checkbox id="cb2" checked="true" text="勾选的复选框"/>
  6. <radiogroup>
  7. <radio text="单选框1"/>
  8. <radio text="单选框2"/>
  9. <radio text="单选框3"/>
  10. </radiogroup>
  11. <radiogroup mariginTop="16">
  12. <radio text="单选框1"/>
  13. <radio text="单选框2"/>
  14. <radio text="勾选的单选框3" checked="true"/>
  15. </radiogroup>
  16. </vertical>
  17. );
  18. ui.cb1.on("check", (checked)=>{
  19. if(checked){
  20. toast("第一个框被勾选了");
  21. }else{
  22. toast("第一个框被取消勾选了");
  23. }
  24. });

7、进度条控件(一)

8、进度条控件(二)

  1. "ui";
  2. ui.layout(
  3. <vertical padding="16">
  4. <text text="处理中..." textColor="black" textSize="16sp"/>
  5. <progressbar />
  6. <text text="直线无限进度条" textColor="black" textSize="16sp" marginTop="24"/>
  7. <progressbar indeterminate="true" style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"/>
  8. <text text="直线进度条" textColor="black" textSize="16sp" marginTop="24"/>
  9. <progressbar progress="30" style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"/>
  10. <text text="可调节进度条" textColor="black" textSize="16sp" marginTop="24"/>
  11. <seekbar progress="20"/>
  12. <horizontal gravity="center" marginTop="24">
  13. <text id="progress_value" textColor="black" textSize="16sp" margin="8" text="0"/>
  14. <progressbar id="progress" w="*" style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"/>
  15. </horizontal>
  16. <button id="download">开始下载</button>
  17. </vertical>
  18. );
  19. var downloadId = null;
  20. ui.download.click(()=>{
  21. if(downloadId != null){
  22. stopDownload();
  23. }else{
  24. startDownload();
  25. }
  26. });
  27. function stopDownload(){
  28. ui.download.text("开始下载");
  29. clearInterval(downloadId);
  30. downloadId = null;
  31. }
  32. function startDownload(){
  33. if(ui.progress.getProgress() == 100){
  34. ui.progress.setProgress(0);
  35. }
  36. ui.download.text("停止下载");
  37. downloadId = setInterval(()=>{
  38. var p = ui.progress.getProgress();
  39. p++;
  40. if(p > 100){
  41. stopDownload();
  42. return;
  43. }
  44. ui.progress.setProgress(p);
  45. ui.progress_value.setText(p.toString());
  46. }, 200);
  47. }

9、卡片布局

  1. "ui";
  2. ui.layout(
  3. <vertical>
  4. <appbar>
  5. <toolbar id="toolbar" title="卡片布局"/>
  6. </appbar>
  7. <card w="*" h="70" margin="10 5" cardCornerRadius="2dp"
  8. cardElevation="1dp" gravity="center_vertical">
  9. <vertical padding="18 8" h="auto">
  10. <text text="写操作系统作业" textColor="#222222" textSize="16sp"/>
  11. <text text="明天第1~2节" textColor="#999999" textSize="14sp"/>
  12. </vertical>
  13. <View bg="#f44336" h="*" w="10"/>
  14. </card>
  15. <card w="*" h="70" margin="10 5" cardCornerRadius="2dp"
  16. cardElevation="1dp" gravity="center_vertical">
  17. <vertical padding="18 8" h="auto">
  18. <text text="修复ui模式的Bug" textColor="#222222" textSize="16sp"/>
  19. <text text="无限期" textColor="#999999" textSize="14sp"/>
  20. </vertical>
  21. <View bg="#ff5722" h="*" w="10"/>
  22. </card>
  23. <card w="*" h="70" margin="10 5" cardCornerRadius="2dp"
  24. cardElevation="1dp" gravity="center_vertical">
  25. <vertical padding="18 8" h="auto">
  26. <text text="发布Auto.js 5.0.0正式版" textColor="#222222" textSize="16sp"/>
  27. <text text="2019年1月" textColor="#999999" textSize="14sp"/>
  28. </vertical>
  29. <View bg="#4caf50" h="*" w="10"/>
  30. </card>
  31. <card w="*" h="70" margin="10 5" cardCornerRadius="2dp"
  32. cardElevation="1dp" gravity="center_vertical">
  33. <vertical padding="18 8" h="auto">
  34. <text text="完成毕业设计和论文" textColor="#222222" textSize="16sp"/>
  35. <text text="2019年4月" textColor="#999999" textSize="14sp"/>
  36. </vertical>
  37. <View bg="#2196f3" h="*" w="10"/>
  38. </card>
  39. </vertical>
  40. );

10、列表控件(一)

11、列表控件(二)

12、列表控件(三)

  1. "ui";
  2. ui.layout(
  3. <frame>
  4. <list id="list">
  5. <vertical>
  6. <text id="name" textSize="16sp" textColor="#000000" text="姓名: {{name}}"/>
  7. <text id="age" textSize="16sp" textColor="#000000" text="年龄: {{age}}岁"/>
  8. <button id="deleteItem" text="删除"/>
  9. </vertical>
  10. </list>
  11. </frame>
  12. );
  13. var items = [
  14. {name: "小明", age: 18}, {name: "小红", age: 30},
  15. {name: "小东", age: 19}, {name: "小强", age: 31},
  16. {name: "小满", age: 20}, {name: "小一", age: 32},
  17. {name: "小和", age: 21}, {name: "小二", age: 1},
  18. {name: "小贤", age: 22}, {name: "小三", age: 2},
  19. {name: "小伟", age: 23}, {name: "小四", age: 3},
  20. {name: "小黄", age: 24}, {name: "小五", age: 4},
  21. {name: "小健", age: 25}, {name: "小六", age: 5},
  22. {name: "小啦", age: 26}, {name: "小七", age: 6},
  23. {name: "小哈", age: 27}, {name: "小八", age: 7},
  24. {name: "小啊", age: 28}, {name: "小九", age: 8},
  25. {name: "小啪", age: 29}, {name: "小十", age: 9}
  26. ];
  27. ui.list.setDataSource(items);
  28. ui.list.on("item_click", function(item, i, itemView, listView){
  29. toast("被点击的人名字为: " + item.name + ",年龄为: " + item.age);
  30. });
  31. ui.list.on("item_bind", function(itemView, itemHolder){
  32. itemView.deleteItem.on("click", function(){
  33. let item = itemHolder.item;
  34. toast("被删除的人名字为: " + item.name + ",年龄为: " + item.age);
  35. items.splice(itemHolder.position, 1);
  36. });
  37. })

13、时间日期选择控件

  1. "ui";
  2. ui.layout(
  3. <scroll>
  4. <vertical padding="16">
  5. <text text="日历样式日期选择" textColor="black" textSize="16sp" marginTop="16"/>
  6. <datepicker />
  7. <text text="滑动日期选择" textColor="black" textSize="16sp" marginTop="16"/>
  8. <datepicker datePickerMode="spinner"/>
  9. <text text="时钟样式时间选择" textColor="black" textSize="16sp" marginTop="16"/>
  10. <timepicker />
  11. <text text="滑动时间选择" textColor="black" textSize="16sp" marginTop="16"/>
  12. <timepicker timePickerMode="spinner"/>
  13. </vertical>
  14. </scroll>
  15. )

14、输入框控件

  1. "ui";
  2. ui.layout(
  3. <vertical padding="16">
  4. <text text="输入框" textColor="black" textSize="16sp" marginTop="16"/>
  5. <input />
  6. <!-- hint属性用来设置输入框的提示-->
  7. <text text="带提示的输入框" textColor="black" textSize="16sp" marginTop="16"/>
  8. <input hint="请输入一些内容"/>
  9. <!-- inputType属性用来设置输入类型,包括number, email, phone等-->
  10. <text text="数字输入框" textColor="black" textSize="16sp" marginTop="16"/>
  11. <input inputType="number" text="123"/>
  12. <!-- password属性用来设置输入框是否是密码输入框 -->
  13. <text text="密码输入框" textColor="black" textSize="16sp" marginTop="16"/>
  14. <input password="true"/>
  15. <!-- lines属性用来设置输入框的行数 -->
  16. <text text="多行输入框" textColor="black" textSize="16sp" marginTop="16"/>
  17. <input lines="3"/>
  18. <text text="设置输入框错误信息" textColor="black" textSize="16sp" marginTop="16"/>
  19. <input id="qq" inputType="number" hint="请输入您的QQ号码"/>
  20. <button id="ok" text="确定" w="auto" style="Widget.AppCompat.Button.Colored"/>
  21. </vertical>
  22. );
  23. ui.ok.click(()=>{
  24. var text = ui.qq.text();
  25. if(text.length == 0){
  26. ui.qq.setError("输入不能为空");
  27. return;
  28. }
  29. var qq = parseInt(text);
  30. if(qq < 10000){
  31. ui.qq.setError("QQ号码格式错误");
  32. return;
  33. }
  34. ui.qq.setError(null);
  35. });

15、图片控件(一)

  1. "ui";
  2. ui.layout(
  3. <scroll>
  4. <vertical bg="#707070" padding="16">
  5. <text text="网络图片" textColor="black" textSize="16sp" marginTop="16"/>
  6. <img src="http://www.autojs.org/assets/uploads/profile/3-profileavatar.png"
  7. w="100" h="100"/>
  8. <text text="带边框的图片" textColor="black" textSize="16sp" marginTop="16"/>
  9. <img src="http://www.autojs.org/assets/uploads/profile/1-profileavatar.jpeg"
  10. w="100" h="100" borderWidth="2dp" borderColor="#202020"/>
  11. <text text="圆形图片" textColor="black" textSize="16sp" marginTop="16"/>
  12. <img src="http://www.autojs.org/assets/uploads/profile/1-profileavatar.jpeg"
  13. w="100" h="100" circle="true"/>
  14. <text text="带边框的圆形图片" textColor="black" textSize="16sp" marginTop="16"/>
  15. <img src="http://www.autojs.org/assets/uploads/profile/1-profileavatar.jpeg"
  16. w="100" h="100" circle="true" borderWidth="2dp" borderColor="#202020"/>
  17. <text text="圆角图片" textColor="black" textSize="16sp" marginTop="16"/>
  18. <img id="rounded_img" src="http://www.autojs.org/assets/uploads/profile/1-profileavatar.jpeg"
  19. w="100" h="100" radius="20dp" scaleType="fitXY"/>
  20. <button id="change_img" text="更改图片"/>
  21. </vertical>
  22. </scroll>
  23. );
  24. ui.change_img.on("click", ()=>{
  25. ui.rounded_img.setSource("http://www.autojs.org/assets/uploads/profile/1-profilecover.jpeg");
  26. });

16、文本控件

  1. "ui";
  2. ui.layout(
  3. <vertical padding="16">
  4. <text textSize="40sp">大字</text>
  5. <text textSize="12sp">小字</text>
  6. <text textStyle="bold" textColor="black">加粗</text>
  7. <text textStyle="italic">斜体</text>
  8. <text textColor="#00ff00">原谅色</text>
  9. <text margin="8">Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。Android操作系统最初由Andy Rubin开发,主要支持手机。20058月由Google收购注资。200711月,Google84家硬件制造商、软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统。</text>
  10. <text maxLines="1" ellipsize="end" margin="8">Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。Android操作系统最初由Andy Rubin开发,主要支持手机。20058月由Google收购注资。200711月,Google84家硬件制造商、软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统。</text>
  11. <text maxLines="2" ellipsize="end" margin="8">Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。Android操作系统最初由Andy Rubin开发,主要支持手机。20058月由Google收购注资。200711月,Google84家硬件制造商、软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统。</text>
  12. <text w="*" gravity="center" textSize="20sp">居中</text>
  13. <text autoLink="all">自动超链接网址www.baidu.com, 邮箱 123@qq.com等</text>
  14. </vertical>
  15. );

17、下拉菜单

  1. "ui";
  2. ui.layout(
  3. <vertical padding="16">
  4. <horizontal>
  5. <text textSize="16sp">下拉菜单</text>
  6. <spinner id="sp1" entries="选项1|选项2|选项3"/>
  7. </horizontal>
  8. <horizontal>
  9. <text textSize="16sp">对话框菜单</text>
  10. <spinner id="sp2" entries="选项4|选项5|选项6" spinnerMode="dialog"/>
  11. </horizontal>
  12. <button id="ok">确定</button>
  13. <button id="select3">选择选项3</button>
  14. </vertical>
  15. );
  16. ui.ok.on("click", ()=>{
  17. var i = ui.sp1.getSelectedItemPosition();
  18. var j = ui.sp2.getSelectedItemPosition();
  19. toast("您的选择是选项" + (i + 1) + "和选项" + (j + 4));
  20. });
  21. ui.select3.on("click", ()=>{
  22. ui.sp1.setSelection(2);
  23. });

18、自定义控件—布局模板

  1. "ui";
  2. var InputLayout = (function() {
  3. //继承至ui.Widget
  4. util.extend(InputLayout, ui.Widget);
  5. function InputLayout() {
  6. ui.Widget.call(this);
  7. this.defineAttr("hint", (view, attr, value, defineSetter)=>{
  8. view._hint.setText(value);
  9. });
  10. this.defineAttr("text", (view, attr, value, defineSetter)=>{
  11. view._input.setText(value);
  12. });
  13. }
  14. InputLayout.prototype.render = function() {
  15. return (
  16. <vertical>
  17. <text id="_hint" textSize="16sp" margin="4" textColor="gray"/>
  18. <input id="_input" margin="0 16"/>
  19. </vertical>
  20. );
  21. }
  22. InputLayout.prototype.getInput = function() {
  23. return this.view._input.getText();
  24. };
  25. ui.registerWidget("input-layout", InputLayout);
  26. return InputLayout;
  27. })();
  28. ui.layout(
  29. <vertical>
  30. <input-layout id="name" hint="请输入名字"/>
  31. <input-layout id="age" hint="请输入年龄" text="18"/>
  32. <button id="ok" text="确认"/>
  33. </vertical>
  34. );
  35. ui.ok.on("click", function(){
  36. toast("名字是:" + ui.name.widget.getInput() + ", 年龄是:" + ui.age.widget.getInput());
  37. });

19、自定义控件—带颜色按钮

  1. "ui";
  2. var ColoredButton = (function() {
  3. //继承ui.Widget
  4. util.extend(ColoredButton, ui.Widget);
  5. function ColoredButton() {
  6. //调用父类构造函数
  7. ui.Widget.call(this);
  8. //自定义属性color,定义按钮颜色
  9. this.defineAttr("color", (view, name, defaultGetter) => {
  10. return this._color;
  11. }, (view, name, value, defaultSetter) => {
  12. this._color = value;
  13. view.attr("backgroundTint", value);
  14. });
  15. //自定义属性onClick,定义被点击时执行的代码
  16. this.defineAttr("onClick", (view, name, defaultGetter) => {
  17. return this._onClick;
  18. }, (view, name, value, defaultSetter) => {
  19. this._onClick = value;
  20. });
  21. }
  22. ColoredButton.prototype.render = function() {
  23. return (
  24. <button textSize="16sp" style="Widget.AppCompat.Button.Colored" w="auto"/>
  25. );
  26. }
  27. ColoredButton.prototype.onViewCreated = function(view) {
  28. view.on("click", () => {
  29. if (this._onClick) {
  30. eval(this._onClick);
  31. }
  32. });
  33. }
  34. ui.registerWidget("colored-button", ColoredButton);
  35. return ColoredButton;
  36. })();
  37. ui.layout(
  38. <vertical>
  39. <colored-button text="第一个按钮" color="#ff5722"/>
  40. <colored-button text="第二个按钮" onClick="hello()"/>
  41. </vertical>
  42. );
  43. function hello() {
  44. alert("Hello ~");
  45. }

20、自定义控件—配置勾选框

  1. "ui";
  2. //这个自定义控件是一个勾选框checkbox,能够保存自己的勾选状态,在脚本重新启动时能恢复状态
  3. var PrefCheckBox = (function() {
  4. //继承至ui.Widget
  5. util.extend(PrefCheckBox, ui.Widget);
  6. function PrefCheckBox() {
  7. //调用父类构造函数
  8. ui.Widget.call(this);
  9. //自定义属性key,定义在配置中保存时的key
  10. this.defineAttr("key");
  11. }
  12. PrefCheckBox.prototype.render = function() {
  13. return (
  14. <checkbox />
  15. );
  16. }
  17. PrefCheckBox.prototype.onFinishInflation = function(view) {
  18. view.setChecked(PrefCheckBox.getPref().get(this.getKey(), false));
  19. view.on("check", (checked) => {
  20. PrefCheckBox.getPref().put(this.getKey(), checked);
  21. });
  22. }
  23. PrefCheckBox.prototype.getKey = function() {
  24. if(this.key){
  25. return this.key;
  26. }
  27. let id = this.view.attr("id");
  28. if(!id){
  29. throw new Error("should set a id or key to the checkbox");
  30. }
  31. return id.replace("@+id/", "");
  32. }
  33. PrefCheckBox.setPref = function(pref) {
  34. PrefCheckBox._pref = pref;
  35. }
  36. PrefCheckBox.getPref = function(){
  37. if(!PrefCheckBox._pref){
  38. PrefCheckBox._pref = storages.create("pref");
  39. }
  40. return PrefCheckBox._pref;
  41. }
  42. ui.registerWidget("pref-checkbox", PrefCheckBox);
  43. return PrefCheckBox;
  44. })();
  45. ui.layout(
  46. <vertical>
  47. <pref-checkbox id="perf1" text="配置1"/>
  48. <pref-checkbox id="perf2" text="配置2"/>
  49. <button id="btn" text="获取配置"/>
  50. </vertical>
  51. );
  52. ui.btn.on("click", function(){
  53. toast("配置1为" + PrefCheckBox.getPref().get("perf1"));
  54. toast("配置2为" + PrefCheckBox.getPref().get("perf2"));
  55. });

21、自定义控件—模块

  1. "ui";
  2. var PrefCheckBox = require('./XXX.js');
  3. ui.layout(
  4. <vertical>
  5. <pref-checkbox id="perf1" text="配置1"/>
  6. <pref-checkbox id="perf2" text="配置2"/>
  7. <button id="btn" text="获取配置"/>
  8. </vertical>
  9. );
  10. ui.btn.on("click", function(){
  11. toast("配置1为" + PrefCheckBox.getPref().get("perf1"));
  12. toast("配置2为" + PrefCheckBox.getPref().get("perf2"));
  13. });

– 脚本对接UI界面


1、准备UI界面和脚本


2、通过开始运行按钮启动脚本


3、设置UI页头和UI页面


3.1、补充:设置页头的颜色


  1. ui.statusBarColor("#ff0000");

4、设置无障碍开启关闭按钮


  1. {/**
  2. * 无障碍服务卡片
  3. **/}
  4. <card w="*" h="40" margin="10" cardCornerRadius="2dp"
  5. cardElevation="1dp" gravity="center_vertical">
  6. <Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="18 8 8 8" textSize="15sp"/>
  7. <View bg="#4caf50" h="*" w="10"/>
  8. </card>
  9. //开启无障碍服务
  10. ui.autoService.on("check", function(checked) {
  11. if(checked && auto.service == null) {
  12. app.startActivity({
  13. action: "android.settings.ACCESSIBILITY_SETTINGS"
  14. });
  15. }
  16. if(!checked && auto.service != null){
  17. auto.service.disableSelf();
  18. }
  19. });
  20. ui.emitter.on("resume", function() {
  21. ui.autoService.checked = auto.service != null;
  22. });

5、设置选择脚本功能下拉框


  1. {/*** 功能选择卡片 **/}
  2. <card w="*" h="40" margin="10 1" cardCornerRadius="2dp"
  3. cardElevation="1dp" gravity="center_vertical">
  4. <horizontal>
  5. <text text="功能选择" padding="18 8 8 8" textSize="15sp" gravity="center_vertical" textColor="black"/>
  6. {/*** 功能选项
  7. **/}
  8. <spinner id="sp1" entries="自动养号|自动顶贴|自动发帖" textColor="blue" marginLeft="20"/>
  9. </horizontal>
  10. <View bg="#ff00ff" h="*" w="10"/>
  11. </card>
  12. //获取下拉框的选中索引
  13. ui.sp1.getSelectedItemPosition()

6、按钮的排列和样式设置


  1. <vertical>
  2. <button text="第一个按钮" marginLeft="10" w="200"/>
  3. <button style="Widget.AppCompat.Button.Colored" id="start" text="开始运行" marginRight="10" w="*"/>
  4. </vertical>

7、设置UI界面中的配置项


  1. <card w="*" h="*" margin="10 5" cardCornerRadius="2dp"
  2. cardElevation="1dp">
  3. <scroll>
  4. <vertical>
  5. </vertical>
  6. </scroll>
  7. </card>

8、简单复选框的使用


  1. <checkbox id="cb_signAll" text="全部签到"/>
  2. var signAll = false;
  3. //签到选择框
  4. ui.cb_signAll.on("check", (checked)=>{
  5. signAll = checked;
  6. });

9、UI界面中复选框如何保存选择状态


10、配置项中的输入框


  1. <horizontal w="*" marginTop="10">
  2. <text layout_gravity="bottom" text="输入一:" textColor="black" textSize="16sp" marginTop="10"/>
  3. <input id="input1" marginLeft="10" layout_gravity="bottom" w="150" text=""/>
  4. </horizontal>

11、如何保存输入框内的值


  1. //创建储存对象
  2. var storage = storages.create("demo数据");
  3. storage.put("input1", ui.input1.text());
  4. var input1 = storage.get("input1");
  5. if(input1 && input1 != ""){
  6. ui.input1.setText(input1);
  7. }

12、开始运行按钮检测无障碍服务


  1. if(auto.service == null) {
  2. toast("请先开启无障碍服务!");
  3. return;
  4. }

13、开始运行按钮启动主函数


  1. main();

14、在脚本中使用UI界面的值(1)


15、在脚本中使用UI界面的值(2)


16、在脚本中使用UI界面的值(3)

0 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
    暂无讨论,说说你的看法吧