UI 组件速查表——Auto.js 支持的全部原生控件
常用组件一览
Button — 按钮
<button id="btn_start" text="开始" w="*" h="auto"/>
<button id="btn_img" text="" bg="#ff0000"/>
Text — 文本标签
<text text="标题" textSize="18sp" textStyle="bold" gravity="center"/>
Input — 输入框
<input id="inp_name" hint="请输入用户名" inputType="text"/>
<input id="inp_pwd" hint="密码" inputType="password"/>
<input id="inp_num" inputType="number"/>
Checkbox / Radio — 复选 / 单选
<checkbox id="chk_agree" text="我同意"/>
<radiogroup>
<radio text="选项 A"/>
<radio text="选项 B"/>
</radiogroup>
Switch — 开关
<switch id="sw_auto" checked="true"/>
Image — 图片
<img src="file:///sdcard/test.png" w="100" h="100"/>
ProgressBar — 进度条
<progressbar id="pb_load" max="100" progress="0"/>
SeekBar — 滑动条
<seekbar id="sb_vol" max="15" progress="5"/>
List — 列表
<list id="list_apps">
<item>
<text id="item_name"/>
</item>
</list>
ui.list_apps.setDataSource(["淘宝", "京东", "支付宝"]);
ui.list_apps.on("item_click", function(item, i) {
toast("点击了:" + item);
});
Scroll — 可滚动容器
<scroll w="*" h="*">
<vertical>
<!-- 很多内容 -->
</vertical>
</scroll>
Tab — 标签页
<tabs id="tabs">
<tab title="任务">
<vertical><text text="任务列表"/></vertical>
</tab>
<tab title="设置">
<vertical><text text="设置项"/></vertical>
</tab>
</tabs>
属性速查
| 属性 | 类型 | 说明 |
|---|
| id | string | 组件 ID,代码中 ui.xxx 访问 |
| text | string | 显示文字 |
| textSize | number/sp | 字号(单位 sp) |
| textColor | color | 文字颜色 #rrggbb 或 #aarrggbb |
| textStyle | bold / italic | 文字样式 |
| bg | color / url | 背景色或图片 |
| w | * / auto / 数字 | 宽度(* 撑满父容器,auto 自适应) |
| h | * / auto / 数字 | 高度 |
| padding | 数字 / 四方向 | 内边距 |
| margin | 数字 / 四方向 | 外边距 |
| gravity | center / top / bottom / left / right | 内部对齐 |
| visibility | visible / invisible / gone | 可见性 |
| inputType | text / password / number / phone | 输入类型 |
| src | url | 图片组件资源 |