android找布局的方法,android – 有没有办法通过adb获取当前活动的布局和视图?...

出于环境原因,我只能使用adb命令.

有没有办法获得当前的布局属性,如ID,位置,文本等?

与uiautomatorviewer显示的相似.

解决方法:

使用adb shell uiautomator dump命令:

Usage: uiautomator [options]

Available subcommands:

help: displays help message

runtest: executes UI automation tests

runtest [options]

: < -c | -e class >

: a list of jar files containing test classes and dependencies. If

the path is relative, it's assumed to be under /data/local/tmp. Use

absolute path if the file is elsewhere. Multiple files can be

specified, separated by space.

: a list of test class names to run, separated by comma. To

a single method, use TestClass#testMethod format. The -e or -c option

may be repeated. This option is not required and if not provided then

all the tests in provided jars will be run automatically.

options:

--nohup: trap SIG_HUP, so test won't terminate even if parent process

is terminated, e.g. USB is disconnected.

-e debug [true|false]: wait for debugger to connect before starting.

-e runner [CLASS]: use specified test runner class instead. If

unspecified, framework default runner will be used.

-e : other name-value pairs to be passed to test classes.

May be repeated.

-e outputFormat simple | -s: enabled less verbose JUnit style output.

dump: creates an XML dump of current UI hierarchy

dump [--verbose][file]

[--compressed]: dumps compressed layout information.

[file]: the location where the dumped XML should be stored, default is

/storage/emulated/legacy/window_dump.xml

events: prints out accessibility events until terminated

默认情况下,它会将视图层次结构转储到$EXTERNAL_STORAGE / window_dump.xml

adb shell uiautomator dump

UI hierchary dumped to: /sdcard/window_dump.xml

通常,您可能希望将该文件提取到PC进行进一步处理,这将是一个额外的步骤.但是有一个巧妙的技巧,它允许将转储和拉入组合成一个命令.使用/ dev / tty作为转储目标将生成一个命令,将整个转储打印到stdout:

adb exec-out uiautomator dump /dev/tty

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>UI hierchary dumped to: /dev/tty

标签:android,adb,android-view,android-uiautomator

来源: https://codeday.me/bug/20190915/1805809.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值