android 查看窗口层级的命令
时间: 2023-10-23 14:11:44 浏览: 82
你可以使用 Android 设备中的 adb 工具来查看当前显示的所有窗口及它们的层级关系。以下是相关命令:
1. 首先,确保你已经将 Android 设备连接到电脑,并且已经打开了开发者选项和 USB 调试模式。
2. 打开命令行界面,输入以下命令:
```
adb shell dumpsys window windows
```
3. 执行该命令后,会输出当前显示的所有窗口及它们的层级关系,包括窗口的名称、ID、类型、位置、大小、可见性等信息。
例如:
```
Window #1xxx8 ApplicationWindowToken{1xx9f1 token=Token{5xxa3 ActivityRecord{1xx6f u0 com.example.app/.MainActivity t1}}}
Window #2xxx8 com.android.internal.policy.PhoneWindow$DecorView{xx0d0e I.E...... R......D 0,0-1920,1080}
Window #3xxx8 android.widget.LinearLayout{xx0d0f V.E...... ......I. 0,0-1920,1080}
Window #4xxx8 android.widget.FrameLayout{xx0d10 V.E...... ......I. 0,72-1920,1080}
Window #5xxx8 android.view.ViewStub{xx0d11 G.E...... ......I. 0,72-1920,1080 #xxxxx}
Window #6xxx8 android.widget.LinearLayout{xx0d12 V.E...... ......I. 0,72-1920,1008}
Window #7xxx8 android.widget.TextView{xx0d13 V.ED..... ......I. 0,0-1920,936 #xxxxx}
Window #8xxx8 android.widget.ListView{xx0d14 VFED.V.. ......I. 0,936-1920,1008 #xxxxx}
```
其中,每一行代表一个窗口,行首的数字为该窗口的唯一标识符,后面是该窗口的属性信息。
注意:这个命令需要在具有 root 权限的设备上运行。如果你的设备没有 root 权限,则只会输出当前应用的窗口信息。