WindowManager会根据窗口的类型来决定Z-Order,通过Z-Order也就决定了窗口从上到下的显示顺序。下表个表明了窗口类型与Z-Order的关系。表中layer值越大表示窗口越靠上。
System
NO. | WINDOW TYPE | 描述 | LAYER | 是否HIDE |
1 | TYPE_UNIVERSE_BACKGROUND | Behind the universe of the real windows. In multiuser systems shows on all users' windows. |
1 | hide |
2 | TYPE_PRIVATE_PRESENTATION | Window for Presentation on top of private virtual display. | 2 | |
3 | TYPE_WALLPAPER | wallpaper window, placed behind any window that wants to sit on top of the wallpaper. In multiuser systems shows only on the owning user's window.wallpaper is at the bottom, though the window manager may move it. |
2 | |
4 | TYPE_PHONE | These are non-application windows providing user interaction with the phone (in particular incoming calls).These windows are normally placed above all applications, but behind the status bar.In multiuser systems shows on all users' windows. | 3 | |
5 | TYPE_SEARCH_BAR | the search bar. There can be only one search bar window; it is placed at the top of the screen. In multiuser systems shows on all users' windows. |
4 | |
6 | TYPE_RECENTS_OVERLAY | Same layer as {@link #TYPE_SYSTEM_DIALOG} but only appears on one user's screen.In multiuser systems shows on all users' windows. | 5 | hide |
7 | TYPE_SYSTEM_DIALOG | panel that slides out from the status bar In multiuser systems shows on all users' windows. | 5 | |
8 | TYPE_TOAST | transient notifications. In multiuser systems shows only on the owning user's window.toasts and the plugged-in battery thing | 6 | |
9 | TYPE_PRIORITY_PHONE | priority phone UI, which needs to be displayed even if the keyguard is active. These windows must not take input focus, or they will interfere with the keyguard. In multiuser systems shows on all users' windows.SIM errors and unlock. Not sure if this really should be in a high layer. | 7 | |
10 | TYPE_DREAM | Dreams (screen saver) window, just above keyguard. In multiuser systems shows only on the owning user's window.used for Dreams (screensavers with TYPE_DREAM windows) | 8 | hide |
11 | TYPE_SYSTEM_ALERT | system window, such as low power alert. These windows are always on top of application windows. In multiuser systems shows only on the owning user's window.like the ANR / app crashed dialogs | 9 | |
12 | TYPE_INPUT_METHOD | internal input methods windows, which appear above the normal UI. Application windows may be resized or panned to keep the input focus visible while this window is displayed. In multiuser systems shows only on the owning user's window. on-screen keyboards and other such input method user interfaces go here. | 10 | |
13 | TYPE_INPUT_METHOD_DIALOG | internal input methods dialog windows, which appear above the current input method window. In multiuser systems shows only on the owning user's window.on-screen keyboards and other such input method user interfaces go here. | 11 | |
14 | TYPE_KEYGUARD_SCRIM | keyguard scrim window. Shows if keyguard needs to be restarted.In multiuser systems shows on all users' windows. the safety window that shows behind keyguard while keyguard is starting | 12 | hide |
15 | TYPE_KEYGUARD | keyguard window.In multiuser systems shows on all users' windows. the keyguard; nothing on top of these can take focus, since they are responsible for power management when displayed. | 13 | |
16 | TYPE_KEYGUARD_DIALOG | dialogs that the keyguard shows In multiuser systems shows on all users' windows. | 14 | |
17 | TYPE_STATUS_BAR_SUB_PANEL | panel that slides out from under the status bar In multiuser systems shows on all users' windows. | 15 | hide |
18 | TYPE_STATUS_BAR | the status bar. There can be only one status bar window; it is placed at the top of the screen, and all other windows are shifted down so they are below it. In multiuser systems shows on all users' windows. | 16 | |
19 | TYPE_STATUS_BAR_PANEL | panel that slides out from over the status bar In multiuser systems shows on all users' windows. | 17 | |
20 | TYPE_VOLUME_OVERLAY | The volume level overlay/dialog shown when the user changes the system volume. In multiuser systems shows on all users' windows.the on-screen volume indicator and controller shown when the user changes the device volume |
18 | hide |
21 | TYPE_SYSTEM_OVERLAY | system overlay windows, which need to be displayed on top of everything else. These windows must not take input focus, or they will interfere with the keyguard. In multiuser systems shows only on the owning user's window.the on-screen volume indicator and controller shown when the user changes the device volume | 19 | |
22 | TYPE_NAVIGATION_BAR | Navigation bar (when distinct from status bar) In multiuser systems shows on all users' windows.the navigation bar, if available, shows atop most things | 20 | hide |
23 | TYPE_NAVIGATION_BAR_PANEL | Navigation bar panel (when navigation bar is distinct from status bar) In multiuser systems shows on all users' windows. some panels (e.g. search) need to show on top of the navigation bar | 21 | hide |
24 | TYPE_SYSTEM_ERROR | internal system error windows, appear on top of everything they can.In multiuser systems shows only on the owning user's window.system-level error dialogs | 22 | |
25 | TYPE_MAGNIFICATION_OVERLAY | Magnification overlay window. Used to highlight the magnified portion of a display when accessibility magnification is enabled.In multiuser systems shows on all users' windows.used to highlight the magnified portion of a display | 23 | hide |
26 | TYPE_DISPLAY_OVERLAY | Display overlay window. Used to simulate secondary display devices.In multiuser systems shows on all users' windows.used to simulate secondary display devices | 24 | hide |
27 | TYPE_DRAG | the drag-and-drop pseudowindow. There is only one drag layer (at most), and it is placed on top of all other windows.In multiuser systems shows only on the owning user's window.the drag layer: input for drag-and-drop is associated with this window,which sits above all other focusable windows | 25 | hide |
28 | TYPE_SECURE_SYSTEM_OVERLAY | secure system overlay windows, which need to be displayed on top of everything else. These windows must not take input focus, or they will interfere with the keyguard.This is exactly like {@link #TYPE_SYSTEM_OVERLAY} except that only the system itself is allowed to create these overlays. Applications cannotobtain permission to create secure system overlays.In multiuser systems shows only on the owning user's window. | 26 | hide |
29 | TYPE_BOOT_PROGRESS | The boot progress dialog, goes on top of everything in the world.In multiuser systems shows on all users' windows. | 27 | hide |
30 | TYPE_POINTER | (mouse) pointer In multiuser systems shows on all users' windows.the (mouse) pointer layer | 28 | hide |
31 | TYPE_HIDDEN_NAV_CONSUMER | Fake window to consume touch events when the navigation bar is hidden. In multiuser systems shows on all users' windows. |
29 | hide |
Application
NO. | WINDOW TYPE | 描述 | LAYER | 是否HIDE |
1 | FIRST_APPLICATION_WINDOW | Start of window types that represent normal application windows. | 2 | |
2 | TYPE_BASE_APPLICATION | an application window that serves as the "base" window of the overall application; all other application windows will appear on top of it.In multiuser systems shows only on the owning user's window. |
2 | |
3 | TYPE_APPLICATION | a normal application window. The {@link #token} must be an Activity token identifying who the window belongs to. In multiuser systems shows only on the owning user's window. | 2 | |
4 | TYPE_APPLICATION_STARTING | special application window that is displayed while the application is starting. Not for use by applications themselves;this is used by the system to display something until the application can show its own windows.In multiuser systems shows on all users' windows. | 2 | |
5 | LAST_APPLICATION_WINDOW | End of types of application windows. | 2 |
Sub Window
NO. | WINDOW TYPE | 描述 | LAYER | 是否HIDE |
1 | FIRST_SUB_WINDOW | 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. | 1 | |
2 | TYPE_APPLICATION_PANEL | a panel on top of an application window. These windows appear on top of their attached window. |
1 | |
3 | TYPE_APPLICATION_ATTACHED_DIALOG | like {@link #TYPE_APPLICATION_PANEL}, but layout of the window happens as that of a top-level window, as a child of its container. | 1 | |
4 | TYPE_APPLICATION_MEDIA | window for showing media (such as video). These windows are displayed behind their attached window. | 1 | |
5 | TYPE_APPLICATION_SUB_PANEL | a sub-panel on top of an application window. These windows are displayed on top their attached window and any {@link #TYPE_APPLICATION_PANEL} panels. | 2 | |
6 | TYPE_APPLICATION_MEDIA_OVERLAY | window for showing overlays on top of media windows. These windows are displayed between TYPE_APPLICATION_MEDIA and the application window. They should be translucent to be useful. This is a big ugly hack so: | -1 | hide |
Media Sublayer(-2) < Media Overlay sublayer (-1) < Main Layer(0) < Attached Dialog (1) < Sub panel Sublayer (2)
子窗口与父窗口共用一个token。的父窗口一般是所在的Activity,比如surfaceView是一个子窗口,他的父窗口是所在activity所在的window。
窗口类型与Layer转换的函数为windowTypeToLayerLw
/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
public int windowTypeToLayerLw(int type) {
if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
return 2;
}
switch (type) {
case TYPE_UNIVERSE_BACKGROUND:
return 1;
case TYPE_WALLPAPER:
// wallpaper is at the bottom, though the window manager may move it.
return 2;
case TYPE_PHONE:
return 3;
case TYPE_SEARCH_BAR:
return 4;
case TYPE_RECENTS_OVERLAY:
case TYPE_SYSTEM_DIALOG:
return 5;
case TYPE_TOAST:
// toasts and the plugged-in battery thing
return 6;
case TYPE_PRIORITY_PHONE:
// SIM errors and unlock. Not sure if this really should be in a high layer.
return 7;
case TYPE_DREAM:
// used for Dreams (screensavers with TYPE_DREAM windows)
return 8;
case TYPE_SYSTEM_ALERT:
// like the ANR / app crashed dialogs
return 9;
case TYPE_INPUT_METHOD:
// on-screen keyboards and other such input method user interfaces go here.
return 10;
case TYPE_INPUT_METHOD_DIALOG:
// on-screen keyboards and other such input method user interfaces go here.
return 11;
case TYPE_KEYGUARD:
// the keyguard; nothing on top of these can take focus, since they are
// responsible for power management when displayed.
return 12;
case TYPE_KEYGUARD_DIALOG:
return 13;
case TYPE_STATUS_BAR_SUB_PANEL:
return 14;
case TYPE_STATUS_BAR:
return 15;
case TYPE_STATUS_BAR_PANEL:
return 16;
case TYPE_VOLUME_OVERLAY:
// the on-screen volume indicator and controller shown when the user
// changes the device volume
return 17;
case TYPE_SYSTEM_OVERLAY:
// the on-screen volume indicator and controller shown when the user
// changes the device volume
return 18;
case TYPE_NAVIGATION_BAR:
// the navigation bar, if available, shows atop most things
return 19;
case TYPE_NAVIGATION_BAR_PANEL:
// some panels (e.g. search) need to show on top of the navigation bar
return 20;
case TYPE_SYSTEM_ERROR:
// system-level error dialogs
return 21;
case TYPE_MAGNIFICATION_OVERLAY:
// used to highlight the magnified portion of a display
return 22;
case TYPE_DISPLAY_OVERLAY:
// used to simulate secondary display devices
return 23;
case TYPE_DRAG:
// the drag layer: input for drag-and-drop is associated with this window,
// which sits above all other focusable windows
return 24;
case TYPE_SECURE_SYSTEM_OVERLAY:
return 25;
case TYPE_BOOT_PROGRESS:
return 26;
case TYPE_POINTER:
// the (mouse) pointer layer
return 27;
case TYPE_HIDDEN_NAV_CONSUMER:
return 28;
}
Log.e(TAG, "Unknown window type: " + type);
return 2;
}
public int subWindowTypeToLayerLw(int type) {
switch (type) {
case TYPE_APPLICATION_PANEL:
case TYPE_APPLICATION_ATTACHED_DIALOG:
return APPLICATION_PANEL_SUBLAYER;
case TYPE_APPLICATION_MEDIA:
return APPLICATION_MEDIA_SUBLAYER;
case TYPE_APPLICATION_MEDIA_OVERLAY:
return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
case TYPE_APPLICATION_SUB_PANEL:
return APPLICATION_SUB_PANEL_SUBLAYER;
}
Log.e(TAG, "Unknown sub-window type: " + type);
return 0;
}