Android查看UI
# adb命令查看
# 查看当前界面Activity
方式一:
adb shell "dumpsys activity top | grep ACTIVITY | tail -n 1"
1
- dumpsys activity top:打印顶层Activity信息
- grep ACTIVITY:从上个命令结果中过滤出Activity相关信息
- tail -n 1:从上一步过滤结果中继续过滤出最后一条记录,也就是当前界面(顶层top)activity
命令执行结果:
ACTIVITY top.iqqcode.schema_deeplink/.MainActivity ca96fdb pid=19441
1
方式二:
adb shell
HNYOK:/ $ dumpsys activity top | grep ACTIVITY
1
2
3
2
3
# 查看当前界面Fragment
adb shell "dumpsys activity top | grep '#0: ' | tail -n 1"1
1
命令执行结果:
#0: DevelopmentSettingsDashboardFragment{d1b926e #1 id=0x7f0a03e2}
1
# 查看Activity任务栈
(仅适用android11以及以上),最好是打断点来查看堆栈吧
命令查看:
adb shell "dumpsys activity activities | grep '* ActivityRecord{'"
1
运行结果
* ActivityRecord{93779f2 u0 com.miui.home/.launcher.Launcher t2}
* ActivityRecord{1fd1f6d u0 com.tencent.mm/.ui.LauncherUI t57}
* ActivityRecord{b2d7811 u0 top.iqqcode.app2/.MainActivity t56}
1
2
3
2
3
windows下可以将下面代码保存成bat文件直接运行:
@echo off &PUSHD %~DP0 &TITLE Settings Tool
:menu
cls
echo Notes: Please connect device with adb, it's only adapter for Android 11.
echo === Menu ===
echo [1] view top activity
echo [2] view top fragment
echo [3] view activity stack
echo ============
set /p user_input=Please choose menu:
if %user_input%==1 goto topActivity
if %user_input%==2 goto topFragment
if %user_input%==3 goto activityStack
if not %user_input%=="" goto menu
:topActivity
adb wait-for-device
adb shell "dumpsys activity top | grep ACTIVITY | tail -n 1"
echo. & pause
goto menu
:topFragment
adb wait-for-device
adb shell "dumpsys activity top | grep '#0: ' | tail -n 1"
echo. & pause
goto menu
:activityStack
adb wait-for-device
adb shell "dumpsys activity activities | grep '* ActivityRecord{'"
echo. & pause
goto menu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
运行结果:
Notes: Please connect device with adb, it's only adapter for Android 11.
=== Menu ===
[1] view top activity
[2] view top fragment
[3] view activity stack
============
Please choose menu:2
#0: AppCategorySelectFragment{4c31805 #0 id=0x7f0a004e}
请按任意键继续. . .
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# UIAutomatorViewer工具
进入Android SDK文件夹,在tools/bin
下的uiautomatorviewer.bat
,命令行进入该目录下运行
该工具是Android SDK自带的;双击可能无响应或者出错,要用命令行运行
# Layout Inspector
官方文档:https://developer.android.google.cn/studio/debug/layout-inspector (opens new window)
编辑 (opens new window)
上次更新: 2022/03/27, 22:58:50