Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Do you know how Android manages complex Window levels?

2025-02-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >

Share

Shulou(Shulou.com)11/24 Report--

App developers do not know whether they have found that StatusBar has been covered on top of App, whether it is to change the color, or to write a suspension box, can not cover StatusBar.

Framework development, there will be some customization, such as covering StatusBar, do not understand may be misused, there are some unnecessary bug, the official document does not list the Window level rules.

So I hope to share with you below how Android sets the rules of the display hierarchy.

Roughly speaking, the concept of Window in Android is also easy to understand, just like often using the Windows operating system, open an application, appear the interface, we can understand that there is a window, so Window ≠ View.

An Activity can understand corresponding to a Window, students who understand the source code know: ViewRootImpl is corresponding to a Window.

What do you think of Window?

Several typical Window extracted by adb shell dumpsys window are as follows: Window # 2 Window {911875c u0 NavigationBar0}: / / Navigation bar ty=NAVIGATION_BAR isOnScreen=true isVisible=trueWindow # 4 Window {bf1a956 u0 StatusBar}: / / status bar ty=STATUS_BAR isOnScreen=true isVisible=trueWindow # 11 Window {d377ae1 u0 InputMethod}: / / input method Do not display ty=INPUT_METHOD isOnScreen=false isVisible=falseWindow # 12 Window {e190206u0 com.android.settings/com.android.settings.Settings}: / / Open App activity ty=BASE_LICATION isOnScreen=true isVisible=trueWindow # 16 Window {abcabb9 u0 com.android.systemui.ImageWallpaper}: / / wallpaper ty=WALLPAPER isOnScreen=false isVisible=false most mobile phones will have the above Window, in a hierarchical order from high to low.

Show PopWindow

Window # 11 Window {513f711 u0 PopupWindow:3e4bfb}: ty=LICATION_SUB_PANEL isOnScreen=true sVisible=true displays Dialog

Window # 11 Window {a08f90b}: ty=LICATION isOnScreen=true isVisible=true, it is not difficult to see that the Window level is related to ty, and ty is short for type.

Classification of Window Application Window: application window type value range [1cm99]

/ * Start of window types that represent normal lication windows. * / public static final int FIRST_LICATION_WINDOW = 1 End of types of lication windows / activity will use this typepublic static final int TYPE_BASE_LICATION = 1 End of types of lication windows / dialog will use this typepublic static final int TYPE_LICATION = 2 role / cold start will display the Window, the screen before the real launch page is displayed: public static final int TYPE_LICATION_STARTING = 3 * * End of types of lication windows. * / public static final int LAST_LICATION_WINDOW = 99 th sub Window: child window: as the name implies, there should be a main window. Child windows need to be attached to the main window, such as PopWindow

Value range of type [1000cr 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_LICATION_PANEL = FIRST_SUB_WINDOW;public static final int TYPE_LICATION_MEDIA = FIRST_SUB_WINDOW + 1 * * public static final int TYPE_LICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2 * * public static final int TYPE_LICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3 * * public static final int TYPE_LICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4 * * public static final int TYPE_LICATION_ABOVE_SUB_PANEL = FIRST_SUB_WINDOW + 5 / * End of types of sub-windows. * / public static final int LAST_SUB_WINDOW = 1999 bot system Window: value range of system window type [2000 dint 2999]

Such as Toast,ANR window, input method, StatusBar,NavigationBar and so on.

/ * Start of system-specific window types. These are not normally * created by lications. * / public static final int FIRST_SYSTEM_WINDOW = 2000 th public static final int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW;public static final int TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1;public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2;/** * End of types of system windows. * / public static final int LAST_SYSTEM_WINDOW = 2999; it seems that I have read the article that the higher the value of type, the higher the level. This view is wrong.

The specific level is the following logic code, the higher the return value, the higher the level, and the closer it is to the user when it is finally displayed on the screen.

Frameworks/base/services/core/java/com/android/server/policy/WindowManagerPolicy.java/** * Returns the layer assignment for the window type. Allows you to control how different * kinds of windows are ordered on-screen. * * @ param type The type of window being assigned. * @ param canAddInternalSystemWindow If the owner window associated with the type we are * evaluating can add internal system windows. I.e they have * {@ link Manifest.permission#INTERNAL_SYSTEM_WINDOW}. If true, alert window * types {@ link android.view.WindowManager.LayoutParams#isSystemAlertWindowType (int)} * can be assigned layers greater than the layer for * {@ link android.view.WindowManager.LayoutParams#TYPE_LICATION_OVERLAY} Else, their * layers would be lesser. * @ param roundedCornerOverlay {# code true} to indicate that the owner window is rounded corner * overlay. * @ return int An arbitrary integer used to order windows, with lower numbers below higher ones. * / default int getWindowLayerFromTypeLw (int type, boolean canAddInternalSystemWindow, boolean roundedCornerOverlay) {/ / Always put the rounded corner layer to the top most. If (roundedCornerOverlay & & canAddInternalSystemWindow) {return getMaxWindowLayer ();} if (type > = FIRST_LICATION_WINDOW & & type

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

IT Information

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report