分两种情况:
第一种情况:
获取autojs脚本自己的ui界面里边的控件。脚本自己的控件,就是写在$ui.layout()里边的控件。
获取子控件数量:ui.abcd.getChildCount()
获取某个子控件:ui.abcd.getChildAt(i)
$ui.layout(
<vertical>
<appbar>
<toolbar id="toolbar" title="起源岛价格监视" />
</appbar>
<viewpager id="viewPager" layout_weight="1">
<frame>
<vertical>
<vertical id = "abcd">
<linear id="container" layout_width="match_parent" layout_height="wrap_content" orientation="horizontal">
<text text="1" textSize="14sp" textColor="#000000" padding="8" />
<text marginLeft="50" w='80' text="石头stone" textSize="14sp" textColor="#000000" padding="8" />
<input id="stonePrice" marginLeft="50" text="400" hint="目标价格" inputType="number" textColor="#000000" padding="8" gravity="center_vertical|center_horizontal" />
<checkbox id="checkbox_stone" text="" marginLeft="50" textColor="#000000" bg="#ffffff" />
</linear>
<linear id="container" layout_width="match_parent" layout_height="wrap_content" orientation="horizontal">
<text text="2" textSize="14sp" textColor="#000000" padding="8" />
<text marginLeft="50" w='80' text="铁iron" textSize="14sp" textColor="#000000" padding="8" />
<input id="ironPrice" marginLeft="50" text="70" hint="目标价格" inputType="number" textColor="#000000" padding="8" gravity="center_vertical|center_horizontal" />
<checkbox id="checkbox_iron" text="" marginLeft="50" textColor="#000000" bg="#ffffff" />
</linear>
<linear id="container" layout_width="match_parent" layout_height="wrap_content" orientation="horizontal">
<text text="7" textSize="14sp" textColor="#000000" padding="8" />
<text marginLeft="50" w='80' text="杉木板 fir board" textSize="14sp" textColor="#000000" padding="8" />
<input id="firBoardPrice" marginLeft="50" text="6" hint="目标价格" inputType="number" textColor="#000000" padding="8" gravity="center_vertical|center_horizontal" />
<checkbox id="checkbox_firBoard" text="" marginLeft="50" textColor="#000000" bg="#ffffff" />
</linear>
</vertical>
<button id="start_at" text="开始监视" />
<View bg="#009688" h="2" margin="0 8" />
</vertical>
</frame>
<frame>
<globalconsole id="globalconsole" w="*" h="*" />
<fab id="fab" src="@drawable/ic_close_black_48dp" w="auto" h="auto" layout_gravity="bottom|right" margin="16" tint="#ffffff" />
</frame>
</viewpager>
<bottomnaviagtion id="navigation" bg="#ffffff" />
</vertical>
);
log(ui.abcd.getChildCount());
log(ui.abcd.getChildAt(0).getChildAt(2).getText());
第二种情况:
通过无障碍获取界面上某个控件UiObject的子控件。一般是别的app的控件,不是脚本自己的控件。
获取子控件数量:childCount()
获取某个子控件:child(i)
var list = className("AbsListView").findOne();
for(var i = 0; i < list.childCount(); i++){
var child = list.child(i);
log(child.className());
}