WindowManager
interface WindowManager : ViewManager
| android.view.WindowManager |
The interface that apps use to talk to the window manager.
Each window manager instance is bound to a Display. To obtain the WindowManager associated with a display, call Context#createWindowContext(Display, int, Bundle) to get the display's UI context, then call Context#getSystemService(String) or Context#getSystemService(Class) on the UI context.
The simplest way to show a window on a particular display is to create a Presentation, which automatically obtains a WindowManager and context for the display.
Summary
| Nested classes | |
|---|---|
| open |
Exception that is thrown when trying to add view whose |
| open |
Exception that is thrown when calling |
| open | |
| Public methods | |
|---|---|
| open Unit |
addCrossWindowBlurEnabledListener(listener: Consumer<Boolean!>)Adds a listener, which will be called when cross-window blurs are enabled/disabled at runtime. |
| open Unit |
addCrossWindowBlurEnabledListener(executor: Executor, listener: Consumer<Boolean!>)Adds a listener, which will be called when cross-window blurs are enabled/disabled at runtime. |
| open WindowMetrics |
Returns the |
| abstract Display! |
Returns the |
| open WindowMetrics |
Returns the largest |
| open Boolean |
Returns whether cross-window blur is currently enabled. |
| open Unit |
removeCrossWindowBlurEnabledListener(listener: Consumer<Boolean!>)Removes a listener, previously added with #addCrossWindowBlurEnabledListener |
| abstract Unit |
removeViewImmediate(view: View!)Special variation of |
| Inherited functions | |
|---|---|
Public methods
addCrossWindowBlurEnabledListener
open fun addCrossWindowBlurEnabledListener(listener: Consumer<Boolean!>): Unit
Adds a listener, which will be called when cross-window blurs are enabled/disabled at runtime. This affects both window blur behind (see LayoutParams#setBlurBehindRadius) and window background blur (see Window#setBackgroundBlurRadius).
Cross-window blur might not be supported by some devices due to GPU limitations. It can also be disabled at runtime, e.g. during battery saving mode, when multimedia tunneling is used or when minimal post processing is requested. In such situations, no blur will be computed or drawn, so the blur target area will not be blurred. To handle this, the app might want to change its theme to one that does not use blurs.
The listener will be called on the main thread.
If the listener is added successfully, it will be called immediately with the current cross-window blur enabled state.
| Parameters | |
|---|---|
listener |
Consumer<Boolean!>: the listener to be added. It will be called back with a boolean parameter, which is true if cross-window blur is enabled and false if it is disabled This value cannot be null. |
addCrossWindowBlurEnabledListener
open fun addCrossWindowBlurEnabledListener(
executor: Executor,
listener: Consumer<Boolean!>
): Unit
Adds a listener, which will be called when cross-window blurs are enabled/disabled at runtime. This affects both window blur behind (see LayoutParams#setBlurBehindRadius) and window background blur (see Window#setBackgroundBlurRadius).
Cross-window blur might not be supported by some devices due to GPU limitations. It can also be disabled at runtime, e.g. during battery saving mode, when multimedia tunneling is used or when minimal post processing is requested. In such situations, no blur will be computed or drawn, so the blur target area will not be blurred. To handle this, the app might want to change its theme to one that does not use blurs.
If the listener is added successfully, it will be called immediately with the current cross-window blur enabled state.
| Parameters | |
|---|---|
executor |
Executor: Executor to handle the listener callback This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. |
listener |
Consumer<Boolean!>: the listener to be added. It will be called back with a boolean parameter, which is true if cross-window blur is enabled and false if it is disabled This value cannot be null. |
getCurrentWindowMetrics
open fun getCurrentWindowMetrics(): WindowMetrics
Returns the WindowMetrics according to the current system state.
The metrics describe the size of the area the window would occupy with MATCH_PARENT width and height, and the WindowInsets such a window would have.
The value of this is based on the current windowing state of the system. For example, for activities in multi-window mode, the metrics returned are based on the current bounds that the user has selected for the Activity's task.
In most scenarios, getCurrentWindowMetrics() rather than getMaximumWindowMetrics() is the correct API to use, since it ensures values reflect window size when the app is not fullscreen.
| Return | |
|---|---|
WindowMetrics |
This value cannot be null. |
getDefaultDisplay
abstract fungetDefaultDisplay(): Display!
Deprecated: Use Context#getDisplay() instead.
Returns the Display upon which this WindowManager instance will create new windows.
Despite the name of this method, the display that is returned is not necessarily the primary display of the system (see Display#DEFAULT_DISPLAY). The returned display could instead be a secondary display that this window manager instance is managing. Think of it as the display that this WindowManager instance uses by default.
To create windows on a different display, you need to obtain a WindowManager for that Display. (See the WindowManager class documentation for more information.)
| Return | |
|---|---|
Display! |
The display that this window manager is managing. |
getMaximumWindowMetrics
open fun getMaximumWindowMetrics(): WindowMetrics
Returns the largest WindowMetrics an app may expect in the current system state.
The value of this is based on the largest potential windowing state of the system. For example, for activities in multi-window mode, the metrics returned are based on the what the bounds would be if the user expanded the Activity's task to cover the entire screen.
The metrics describe the size of the largest potential area the window might occupy with MATCH_PARENT width and height, and the WindowInsets such a window would have.
Note that this might still be smaller than the size of the physical display if certain areas of the display are not available to windows created in this Context. For example, given that there's a device which have a multi-task mode to limit activities to a half screen. In this case, getMaximumWindowMetrics() reports the bounds of the half screen which the activity is located.
Generally getCurrentWindowMetrics() is the correct API to use for choosing UI layouts. getMaximumWindowMetrics() are only appropriate when the application needs to know the largest possible size it can occupy if the user expands/maximizes it on the screen.
| Return | |
|---|---|
WindowMetrics |
This value cannot be null. |
isCrossWindowBlurEnabled
open fun isCrossWindowBlurEnabled(): Boolean
Returns whether cross-window blur is currently enabled. This affects both window blur behind (see LayoutParams#setBlurBehindRadius) and window background blur (see Window#setBackgroundBlurRadius).
Cross-window blur might not be supported by some devices due to GPU limitations. It can also be disabled at runtime, e.g. during battery saving mode, when multimedia tunneling is used or when minimal post processing is requested. In such situations, no blur will be computed or drawn, so the blur target area will not be blurred. To handle this, the app might want to change its theme to one that does not use blurs. To listen for cross-window blur enabled/disabled events, use #addCrossWindowBlurEnabledListener.
removeCrossWindowBlurEnabledListener
open fun removeCrossWindowBlurEnabledListener(listener: Consumer<Boolean!>): Unit
Removes a listener, previously added with #addCrossWindowBlurEnabledListener
| Parameters | |
|---|---|
listener |
Consumer<Boolean!>: the listener to be removed This value cannot be null. |
See Also
removeViewImmediate
abstract fun removeViewImmediate(view: View!): Unit
Special variation of removeView that immediately invokes the given view hierarchy's View.onDetachedFromWindow() methods before returning. This is not for normal applications; using it correctly requires great care.
| Parameters | |
|---|---|
view |
View!: The view to be removed. |