autojs获取子控件的数量childCount和获取子控件child

分两种情况:

第一种情况:

获取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());
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值