赞
踩
App开发者的不知有没有发现,StatusBar 一直是盖在App 上面,不管是修改颜色,或者是写悬浮框,都无法盖住StatusBar。framework 开发,会出现一些定制,如盖住 StatusBar,不了解的可能用错,出现一些不必要的bug,官方文档也没有列出 Window 层级的规则。
所以希望通过下文给大家分享,Android 是如何制定显示层级规则的。
其实也可以好理解,和经常使用 Windows 操作系统一样,打开一个应用,出现界面,我们可以理解出现了一个窗口,所以 Window ≠ View
一个Activity 可以理解 对应一个 Window,理解源码的同学知道: ViewRootImpl 是对应一个 Window。
怎么看 Window 呢?
adb shell dumpsys window 抽取了几个典型的Window如下: Window #2 Window{911875c u0 NavigationBar0}://导航栏 ty=NAVIGATION_BAR isOnScreen=true isVisible=true Window #4 Window{bf1a956 u0 StatusBar}://状态栏 ty=STATUS_BAR isOnScreen=true isVisible=true Window #11 Window{d377ae1 u0 InputMethod}://输入法,不显示 ty=INPUT_METHOD isOnScreen=false isVisible=false Window #12 Window{e190206 u0 com.android.settings/com.android.settings.Settings}://打开 App activity ty=BASE_APPLICATION isOnScreen=true isVisible=true Window #16 Window{abcabb9 u0 com.android.systemui.ImageWallpaper}://壁纸 ty=WALLPAPER isOnScreen=false isVisible=false
一般手机都会存在以上 Window,层级顺序从高 -> 低。
显示PopWindow
Window #11 Window{513f711 u0 PopupWindow:3e4bfb}:
ty=APPLICATION_SUB_PANEL
isOnScreen=true
sVisible=true
显示Dialog
Window #11 Window{a08f90b ...}:
ty=APPLICATION
isOnScreen=true
isVisible=true
不难看出,Window 层级与 ty
有关系的,ty
是 type
的简写。
type 取值范围 [1,99]
/** * Start of window types that represent normal application windows. */ public static final int FIRST_APPLICATION_WINDOW = 1; // activity 会使用 此 type public static final int TYPE_BASE_APPLICATION = 1; // dialog 会使用 此 type public static final int TYPE_APPLICATION = 2; // 冷启动会显示的 Window,真正启动页面显示之前的画面 public static final int TYPE_APPLICATION_STARTING = 3; // 没玩过 public static final int TYPE_DRAWN_APPLICATION = 4; /** * End of types of application windows. */ public static final int LAST_APPLICATION_WINDOW = 99;
子窗口:顾名思义,对应有主窗口。子窗口需要附在主窗口上,如PopWindow
type 取值范围 [1000,1999]
/**
* Start of types of sub-windows. The {@link #token} of these windows
* must be set to the window they are attached to. These types of
* windows are kept next to their attached window in Z-order, and their
* coordinate space is relative to their attached window.
*/
public static final int FIRST_SUB_WINDOW = 1000;
public static final int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW;
public static final int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1;
public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2;
public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3;
public static final int TYPE_APPLICATION_MEDIA_OVERLAY
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。