Android窗口类型

来源:互联网 发布:那些引擎源码能用 编辑:程序博客网 时间:2024/06/03 03:12

WindowManager会根据窗口的类型来决定Z-Order,通过Z-Order也就决定了窗口从上到下的显示顺序。下表个表明了窗口类型与Z-Order的关系。表中layer值越大表示窗口越靠上


System

NO.WINDOW TYPE描述LAYER是否HIDE1TYPE_UNIVERSE_BACKGROUNDBehind the universe of the real windows.
In multiuser systems shows on all users' windows.1hide2TYPE_PRIVATE_PRESENTATIONWindow for Presentation on top of private virtual display.23TYPE_WALLPAPERwallpaper 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.24TYPE_PHONEThese 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.35TYPE_SEARCH_BARthe 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.46TYPE_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.5hide7TYPE_SYSTEM_DIALOGpanel that slides out from the status bar In multiuser systems shows on all users' windows.58TYPE_TOASTtransient notifications. In multiuser systems shows only on the owning user's window.toasts and the plugged-in battery thing69TYPE_PRIORITY_PHONEpriority 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.710TYPE_DREAMDreams (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)8hide11TYPE_SYSTEM_ALERTsystem 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 dialogs912TYPE_INPUT_METHODinternal 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.1013TYPE_INPUT_METHOD_DIALOGinternal 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.1114TYPE_KEYGUARD_SCRIMkeyguard 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 starting12hide15TYPE_KEYGUARDkeyguard 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.1316TYPE_KEYGUARD_DIALOGdialogs that the keyguard shows In multiuser systems shows on all users' windows.1417TYPE_STATUS_BAR_SUB_PANELpanel that slides out from under the status bar In multiuser systems shows on all users' windows.15hide18TYPE_STATUS_BARthe 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.1619TYPE_STATUS_BAR_PANELpanel that slides out from over the status bar In multiuser systems shows on all users' windows.1720TYPE_VOLUME_OVERLAYThe 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 volume18hide21TYPE_SYSTEM_OVERLAYsystem 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 volume1922TYPE_NAVIGATION_BARNavigation bar (when distinct from status bar) In multiuser systems shows on all users' windows.the navigation bar, if available, shows atop most things20hide23TYPE_NAVIGATION_BAR_PANELNavigation 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 bar21hide24TYPE_SYSTEM_ERRORinternal system error windows, appear on top of everything they can.In multiuser systems shows only on the owning user's window.system-level error dialogs2225TYPE_MAGNIFICATION_OVERLAYMagnification 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 display23hide26TYPE_DISPLAY_OVERLAYDisplay overlay window.  Used to simulate secondary display devices.In multiuser systems shows on all users' windows.used to simulate secondary display devices24hide27TYPE_DRAGthe 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 windows25hide28TYPE_SECURE_SYSTEM_OVERLAYsecure 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.26hide29TYPE_BOOT_PROGRESSThe boot progress dialog, goes on top of everything in the world.In multiuser systems shows on all users' windows.27hide30TYPE_POINTER(mouse) pointer In multiuser systems shows on all users' windows.the (mouse) pointer layer28hide31TYPE_HIDDEN_NAV_CONSUMERFake window to consume touch events when the navigation
 bar is hidden. In multiuser systems shows on all users' windows.29hide

Application

NO.WINDOW TYPE描述LAYER是否HIDE1FIRST_APPLICATION_WINDOWStart of window types that represent normal application windows.22TYPE_BASE_APPLICATIONan 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.23TYPE_APPLICATIONa 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.24TYPE_APPLICATION_STARTINGspecial 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.25LAST_APPLICATION_WINDOWEnd of types of application windows.2

Sub Window

NO.WINDOW TYPE描述LAYER是否HIDE1FIRST_SUB_WINDOWStart 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.12TYPE_APPLICATION_PANELa panel on top of an application window.  These windows
 appear on top of their attached window.13TYPE_APPLICATION_ATTACHED_DIALOGlike {@link #TYPE_APPLICATION_PANEL}, but layout of the window happens as that of a top-level window, as a child of its container.14TYPE_APPLICATION_MEDIAwindow for showing media (such as video).  These windows are displayed behind their attached window.15TYPE_APPLICATION_SUB_PANELa sub-panel on top of an application window.  These windows are displayed on top their attached window and any {@link #TYPE_APPLICATION_PANEL} panels.26TYPE_APPLICATION_MEDIA_OVERLAYwindow 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:-1hideSub Window对应的主窗口为0

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;    }

1).  Window类的基本属性如下:

          FEATURE_OPTIONS_PANEL = 0;                      可选的Panel标志(默认使能)
          FEATURE_NO_TITLE = 1;                                 无标题栏
          FEATURE_PROGRESS = 2;                                 标题栏上显示加载进度,如webview加载网页时(条状进度条)
          FEATURE_LEFT_ICON = 3;                                标题栏左侧显示一个图标
          FEATURE_RIGHT_ICON = 4;                              标题栏右侧显示一个图标
          FEATURE_INDETERMINATE_PROGRESS = 5;   不确定的进度(圆圈状等待图标)
          FEATURE_CONTEXT_MENU = 6;                        Menu菜单(默认使能)
          FEATURE_CUSTOM_TITLE = 7;                          自定义标题栏,该属性不能与其他标题栏属性合用
          FEATURE_ACTION_BAR = 8;                               ActionBar属性,ActionBar显示的,TitleBar就没有啦                                                             

          FEATURE_ACTION_BAR_OVERLAY = 9;            覆盖在内容之上的ActionBar

          FEATURE_ACTION_MODE_OVERLAY = 10;        AcitionBar的覆盖在内容的模式

          FEATURE_OPENGL = 8;                                       若开启OpenGL,那么2D将由OpenGL处理(OpenGL中2D是3D的子集)
          PROGRESS_VISIBILITY_ON = -1;                         进度条可见
          PROGRESS_VISIBILITY_OFF = -2;                       进度条不可见
          PROGRESS_INDETERMINATE_ON = -3;              开启不确定模式
          PROGRESS_INDETERMINATE_OFF = -4;             关闭不确定模式
          PROGRESS_START = 0;                                        第一进度条的最小值
          PROGRESS_END = 10000;                                     第一进度条的最大值
          PROGRESS_SECONDARY_START = 20000;          第二进度条的最小值
          PROGRESS_SECONDARY_END = 30000;              第二进度条的最大值

       经常使用到的:

    1、隐藏标题栏

        requestWindowFeature(Window.FEATURE_NO_TITLE);

    2、在标题栏显示进度条

        requestWindowFeature(Window.FEATURE_PROGRESS);

        setContentView(R.layout.progressbar_1);

        setProgressBarVisibility(true);

        final ProgressBar progressHorizontal = (ProgressBar)findViewById(R.id.progress_horizontal);

        setProgress(progressHorizontal.getProgress() * 100);

        setSecondaryProgress(progressHorizontal.getSecondaryProgress()* 100);

    3、使用自定义标题栏

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

        setContentView(R.layout.xxx);

        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.my_title_bar);

    4、清除标题栏内容,而区域保留

        ((ViewGroup)getWindow().findViewById(com.android.internal.R.id.title_container)).removeAllViews();

    5、隐藏标题栏

        ((ViewGroup)getWindow(). findViewById(com.android.internal.R.id.title_container)).setVisibility(View.GONE);

    6、显示标题栏

        ((ViewGroup)getWindow(). findViewById(com.android.internal.R.id.title_container)).setVisibility(View.VISIBLE);

    注意事项

    (1) requestWindowFeature()要在setContentView()之前调用;

    (2) 设置各种Feature,是具有排它性的,一旦设置,后续不可更改为别的类型;

    (3)当使用TabHost(由ActivityGroup派生)时,各个Tab里的Activity,要么都是NO_TITLE,要么都是CUSTOM_TITLE,无法分别进行设置

    ID_ANDROID_CONTENT = com.android.internal.R.id.content;  就是显示内容的id。


    2). Window类的内部类接口Callback包含一系列dispatchXxxx函数和一系列onXxxx函数,用于处理UI事件

        public boolean dispatchKeyEvent(KeyEvent event);

        public boolean dispatchKeyShortcutEvent(KeyEvent event);

        public boolean dispatchTouchEvent(MotionEvent event);

        public boolean dispatchTrackballEvent(MotionEvent event);

        public boolean dispatchGenericMotionEvent(MotionEvent event);                            移动事件

        public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);

        public View onCreatePanelView(int featureId);

        public boolean onCreatePanelMenu(int featureId, Menu menu);

        public boolean onPreparePanel(int featureId, View view, Menu menu);

        public boolean onMenuOpened(int featureId, Menu menu);                                      用户选择菜单项。

        public boolean onMenuItemSelected(int featureId, MenuItem item);                          用户选择菜单项。

        public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);        当前窗口属性改变。

        public void onContentChanged();                                  窗口的view发生改变。

        public void onWindowFocusChanged(boolean hasFocus);窗口的焦点发生变换

        public void onAttachedToWindow();                              窗口附加到窗口管理器上。

        public void onDetachedFromWindow();                          窗口从窗口管理器上摘除。

        public void onPanelClosed(int featureId, Menu menu);

        public boolean onSearchRequested();                       当用户按下了search按钮。如果启动了搜索界面则返回true,如果不能执行则返回false。

        public ActionMode onWindowStartingActionMode(ActionMode.Callback callback);

        public void onActionModeStarted(ActionMode mode);

        public void onActionModeFinished(ActionMode mode);

1 0
原创粉丝点击