EasyClik安卓原生UI免费版教程
免费教程说明
UI入门
EasyClick 官方支持的安卓组件
排版绘制
↗
布局
↗
LinearLayout 线性布局
RadioGroup 单选布局
ScrollView 垂直滚动框布局
FrameLayout 帧布局
HorizontalScrollView 横向滚动框
CardView卡片布局
include 引用布局
控件
↗
TextView 控件
View 视图
EditText 输入框控件
Button 按钮控件
CheckBox 复选框
RadioButton 单选按钮
Spinner 下拉选择框
Swtich 开关按钮
ImageView 图像
WebView 内嵌浏览器
公有属性表
人机交互
↗
按钮点击操作
单选按钮,复选框,开关选中操作
下拉框选中操作
修改文本内容
保存UI参数脚本读取值
UI中启动脚本
UI中启动EC设置
清空UI参数
对话框
悬浮窗
脚本与 UI 交互
UI与网络交互
原生UI 学习思路
本站点使用 MrDoc 构建
-
+
单选按钮,复选框,开关选中操作
# 单选按钮,复选框,开关选中操作 >s 单选 复选 开关 一起讲解,因为这三种组件的监听事件类型一样,并且值只有两种 true 或者false 即选中了或者没选中 ## 交互逻辑 >s 先在xml里绘制 这三个组件 单选,复选,开关 ,这里面这三种组件都需要设置tag属性值 >d 在ui.js里分别写这三个组件的监听事件,这里的监听对象为xml里的三个组件对应的tag属性的对象 ## xml 示例 ```xml <?xml version="1.0" encoding="UTF-8" ?> <ScrollView xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:android="http://schemas.android.com/apk/res/android" xsi:noNamespaceSchemaLocation="layout.xsd" android:layout_height="match_parent" android:layout_width="match_parent"> <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" android:padding="20dp"> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:layout_width="wrap_parent" android:layout_height="wrap_content" android:text="桃子" android:tag="radio_btn1"/> <RadioButton android:layout_width="wrap_parent" android:layout_height="wrap_content" android:text="梨子" android:tag="radio_btn2"/> <RadioButton android:layout_width="wrap_parent" android:layout_height="wrap_content" android:text="苹果" android:tag="radio_btn3"/> </RadioGroup> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <CheckBox android:layout_width="wrap_parent" android:layout_height="wrap_content" android:text="看书" android:tag="cb_1"/> <CheckBox android:layout_width="wrap_parent" android:layout_height="wrap_content" android:text="跳舞" android:tag="cb_2"/> <CheckBox android:layout_width="wrap_parent" android:layout_height="wrap_content" android:text="唱歌" android:tag="cb_3"/> </LinearLayout> <Switch android:layout_width="match_parent" android:layout_height="wrap_content" android:text="自动化服务状态" android:tag="acc_service"/> </LinearLayout> </ScrollView> ``` ## ui.js 示例 ```js function main() { ui.layout("参数设置", "main.xml"); ui.setUIvar();// 初始化并将所有xml里的组件转为对象 // 单选按钮, 复选框,开关 这三种类型的监听事件类型一样 为 checkedChange // 参数解释 // 第一个参数为 xml 文件里对应的组件 tag属性的值 // 第二个参数为 事件类型 checkedChange 选中类型 // 第三个参数为 回调函数 选中或者没选中的状态回调 有两个参数 第一个参数 view是自身 第二个是 isChecked 代表选中的状态 (已选或者取消选中) 为布尔值类型 ui.setEvent("radio_btn1","checkedChange",function (view,isChecked) { if (isChecked) { toast("选中了"+view.getText()); } }) ui.setEvent("radio_btn2","checkedChange",function (view,isChecked) { if (isChecked) { toast("选中了"+view.getText()); } }) ui.setEvent("radio_btn3","checkedChange",function (view,isChecked) { if (isChecked) { toast("选中了"+view.getText()); } }) ui.setEvent("cb_1","checkedChange",function (view,isChecked) { if (isChecked) { toast("选中了"+view.getText()); } }) ui.setEvent("cb_2","checkedChange",function (view,isChecked) { if (isChecked) { toast("选中了"+view.getText()); } }) ui.setEvent("cb_3","checkedChange",function (view,isChecked) { if (isChecked) { toast("选中了"+view.getText()); } }) ui.setEvent("acc_service","checkedChange",function (view,isChecked) { if (isChecked) { toast("开启自动化服务"); ui.startEnvAsync(function (r) { if (r) { toast("自动化服务开启成功"); }else{ toast("自动化服务开启失败"); } }) }else{ toast("关闭自动化服务"); closeEnv(true) } }) } main(); ``` 我是Mr-老鬼、QQ1156346325 -------------------------版权声明---------------------- 版权所有~Mr-老鬼 ~转载请注明原文地址。 免责声明:本文所有的教程仅限交流学习使用不得用于违法用途,造成的法律后果本人不承担责任。
Mr、老鬼
2024年1月24日 01:29
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
PDF文档(打印)
分享
链接
类型
密码
更新密码