WindowInsetsCompat
class WindowInsetsCompat
Describes a set of insets for window content.
WindowInsetsCompats are immutable and may be expanded to include more inset types in the future. To adjust insets, use one of the supplied clone methods to obtain a new WindowInsetsCompat instance with the adjusted properties.
Summary
Nested types |
|---|
|
Builder for |
class WindowInsetsCompat.SideClass that defines different sides for insets. |
class WindowInsetsCompat.TypeClass that defines different types of sources causing window insets. |
Constants |
|
|---|---|
const WindowInsetsCompat |
A |
Public constructors |
|---|
|
Constructs a new WindowInsetsCompat, copying all values from a source WindowInsetsCompat. |
Public functions |
|
|---|---|
WindowInsetsCompat |
This function is deprecated. Consuming of different parts individually of a |
WindowInsetsCompat |
This function is deprecated. Consuming of different parts individually of a |
WindowInsetsCompat |
This function is deprecated. Consuming of different parts individually of a |
Boolean |
|
DisplayCutoutCompat? |
Returns the display cutout if there is one. |
Insets |
Returns the insets of a specific set of windows causing insets, denoted by the |
Insets |
getInsetsIgnoringVisibility(typeMask: Int)Returns the insets a specific set of windows can cause, denoted by the |
Insets |
This function is deprecated. Use |
Rect? |
Returns a |
RoundedCornerCompat? |
getRoundedCorner(position: Int)Returns the |
Int |
This function is deprecated. Use |
Int |
This function is deprecated. Use |
Int |
This function is deprecated. Use |
Int |
This function is deprecated. Use |
Insets |
This function is deprecated. Use |
Insets |
This function is deprecated. Use |
Int |
This function is deprecated. Use |
Int |
This function is deprecated. Use |
Int |
This function is deprecated. Use |
Int |
This function is deprecated. Use |
Insets |
This function is deprecated. Use |
Insets |
This function is deprecated. Use |
Boolean |
Returns true if this WindowInsets has any non-zero insets. |
Boolean |
This function is deprecated. Use |
Boolean |
This function is deprecated. Use |
Int |
hashCode() |
WindowInsetsCompat |
Returns a copy of this instance inset in the given directions. |
WindowInsetsCompat |
inset(Returns a copy of this instance inset in the given directions. |
Boolean |
Check if these insets have been fully consumed. |
Boolean |
isRound()Returns true if the associated window has a round shape. |
Boolean |
Returns whether a set of windows that may cause insets is currently visible on screen, regardless of whether it actually overlaps with this window. |
WindowInsetsCompat |
This function is deprecated. use |
WindowInsetsCompat |
This function is deprecated. use |
WindowInsets? |
@RequiresApi(value = 20)Return the source |
java-static WindowInsetsCompat |
@RequiresApi(value = 20)Wrap an instance of |
java-static WindowInsetsCompat |
@RequiresApi(value = 20)Wrap an instance of |
Constants
CONSUMED
const val CONSUMED: WindowInsetsCompat
A WindowInsetsCompat instance for which isConsumed returns true.
This can be used during insets dispatch in the view hierarchy by returning this value from View.onApplyWindowInsets(WindowInsets) or onApplyWindowInsets to stop dispatch the insets to its children to avoid traversing the entire view hierarchy.
The application should return this instance once it has taken care of all insets on a certain level in the view hierarchy, and doesn't need to dispatch to its children anymore for better performance.
| See also | |
|---|---|
isConsumed |
Public constructors
WindowInsetsCompat
WindowInsetsCompat(src: WindowInsetsCompat?)
Constructs a new WindowInsetsCompat, copying all values from a source WindowInsetsCompat.
| Parameters | |
|---|---|
src: WindowInsetsCompat? |
source from which values are copied |
Public functions
funconsumeDisplayCutout(): WindowInsetsCompat
Returns a copy of this WindowInsets with the cutout fully consumed.
When running on platforms with API 27 and below, this method is a no-op.
| Returns | |
|---|---|
WindowInsetsCompat |
A modified copy of this WindowInsets |
funconsumeStableInsets(): WindowInsetsCompat
Returns a copy of this WindowInsets with the stable insets fully consumed.
When running on platforms with API 20 and below, this method always returns null.
| Returns | |
|---|---|
WindowInsetsCompat |
A modified copy of this WindowInsetsCompat |
funconsumeSystemWindowInsets(): WindowInsetsCompat
Returns a copy of this WindowInsets with the system window insets fully consumed.
When running on platforms with API 19 and below, this method always returns null.
| Returns | |
|---|---|
WindowInsetsCompat |
A modified copy of this WindowInsets |
getDisplayCutout
fun getDisplayCutout(): DisplayCutoutCompat?
Returns the display cutout if there is one.
When running on platforms with API 27 and below, this method always returns null.
| Returns | |
|---|---|
DisplayCutoutCompat? |
the display cutout or null if there is none |
| See also | |
|---|---|
DisplayCutoutCompat |
getInsets
fun getInsets(typeMask: Int): Insets
Returns the insets of a specific set of windows causing insets, denoted by the typeMask bit mask of Types. When running on devices with API Level 29 and before, the returned insets are an approximation based on the information available. This is especially true for the IME type, which currently only works when running on devices with SDK level 23 and above.
| Returns | |
|---|---|
Insets |
The insets. |
getInsetsIgnoringVisibility
fun getInsetsIgnoringVisibility(typeMask: Int): Insets
Returns the insets a specific set of windows can cause, denoted by the typeMask bit mask of Types, regardless of whether that type is currently visible or not.
The insets represents the area of a a window that that may be partially or fully obscured by the system window identified by typeMask. This value does not change based on the visibility state of those elements. For example, if the status bar is normally shown, but temporarily hidden, the inset returned here will still provide the inset associated with the status bar being shown.
IME type, which currently only works when running on devices with SDK level 23 and above.
| Returns | |
|---|---|
Insets |
The insets. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If the caller tries to query |
fungetMandatorySystemGestureInsets(): Insets
Returns the mandatory system gesture insets.
The mandatory system gesture insets represent the area of a window where mandatory system gestures have priority and may consume some or all touch input, e.g. due to the a system bar occupying it, or it being reserved for touch-only gestures.
| See also | |
|---|---|
getMandatorySystemGestureInsets |
getPrivacyIndicatorBounds
fun getPrivacyIndicatorBounds(): Rect?
Returns a Rect representing the bounds of the system privacy indicator, for the current orientation, in the window space coordinates. This method returns null if the system component doesn't have such indicators or the bounds have been consumed.
getRoundedCorner
fun getRoundedCorner(position: Int): RoundedCornerCompat?
Returns the RoundedCornerCompat of the given position if there is one.
| Parameters | |
|---|---|
position: Int |
the position of the rounded corner on the display. The value should be one of the following: |
| Returns | |
|---|---|
RoundedCornerCompat? |
the rounded corner of the given position. Returns |
fungetStableInsetBottom(): Int
Returns the bottom stable inset in pixels.
The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns 0.
| Returns | |
|---|---|
Int |
The bottom stable inset |
fungetStableInsetLeft(): Int
Returns the left stable inset in pixels.
The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns 0.
| Returns | |
|---|---|
Int |
The left stable inset |
fungetStableInsetRight(): Int
Returns the right stable inset in pixels.
The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns 0.
| Returns | |
|---|---|
Int |
The right stable inset |
fungetStableInsetTop(): Int
Returns the top stable inset in pixels.
The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns 0.
fungetStableInsets(): Insets
Returns the stable insets in pixels.
The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.
| Returns | |
|---|---|
Insets |
The stable insets |
fungetSystemGestureInsets(): Insets
Returns the system gesture insets.
The system gesture insets represent the area of a window where system gestures have priority and may consume some or all touch input, e.g. due to the a system bar occupying it, or it being reserved for touch-only gestures.
An app can declare priority over system gestures with setSystemGestureExclusionRects outside of the mandatory system gesture insets.
| See also | |
|---|---|
getSystemGestureInsets |
fungetSystemWindowInsetBottom(): Int
Returns the bottom system window inset in pixels.
The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.
When running on platforms with API 19 and below, this method always returns 0.
| Returns | |
|---|---|
Int |
The bottom system window inset |
fungetSystemWindowInsetLeft(): Int
Returns the left system window inset in pixels.
The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.
When running on platforms with API 19 and below, this method always returns 0.
| Returns | |
|---|---|
Int |
The left system window inset |
fungetSystemWindowInsetRight(): Int
Returns the right system window inset in pixels.
The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.
When running on platforms with API 19 and below, this method always returns 0.
| Returns | |
|---|---|
Int |
The right system window inset |
fungetSystemWindowInsetTop(): Int
Returns the top system window inset in pixels.
The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.
When running on platforms with API 19 and below, this method always returns 0.
| Returns | |
|---|---|
Int |
The top system window inset |
fungetSystemWindowInsets(): Insets
Returns the system window insets in pixels.
The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.
| Returns | |
|---|---|
Insets |
The system window insets |
fungetTappableElementInsets(): Insets
Returns the tappable element insets.
The tappable element insets represent how much tappable elements must at least be inset to remain both tappable and visually unobstructed by persistent system windows.
This may be smaller than getSystemWindowInsets if the system window is largely transparent and lets through simple taps (but not necessarily more complex gestures).
| See also | |
|---|---|
getTappableElementInsets |
hasInsets
fun hasInsets(): Boolean
Returns true if this WindowInsets has any non-zero insets.
When running on platforms with API 19 and below, this method always returns false.
| Returns | |
|---|---|
Boolean |
true if any inset values are nonzero |
funhasStableInsets(): Boolean
Returns true if this WindowInsets has nonzero stable insets.
The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns false.
| Returns | |
|---|---|
Boolean |
true if any of the stable inset values are nonzero |
funhasSystemWindowInsets(): Boolean
Returns true if this WindowInsets has nonzero system window insets.
The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.
When running on platforms with API 19 and below, this method always returns false.
| Returns | |
|---|---|
Boolean |
true if any of the system window inset values are nonzero |
inset
fun inset(insets: Insets): WindowInsetsCompat
Returns a copy of this instance inset in the given directions. This is intended for dispatching insets to areas of the window that are smaller than the current area.
Example:
childView.dispatchApplyWindowInsets(insets.inset(childMargins));
| Parameters | |
|---|---|
insets: Insets |
the amount of insets to remove from all sides. |
| See also | |
|---|---|
inset |
inset
fun inset(
left: @IntRange(from = 0) Int,
top: @IntRange(from = 0) Int,
right: @IntRange(from = 0) Int,
bottom: @IntRange(from = 0) Int
): WindowInsetsCompat
Returns a copy of this instance inset in the given directions. This is intended for dispatching insets to areas of the window that are smaller than the current area.
Example:
childView.dispatchApplyWindowInsets(insets.inset( childMarginLeft, childMarginTop, childMarginBottom, childMarginRight));
| Parameters | |
|---|---|
left: @IntRange(from = 0) Int |
the amount of insets to remove from the left. Must be non-negative. |
top: @IntRange(from = 0) Int |
the amount of insets to remove from the top. Must be non-negative. |
right: @IntRange(from = 0) Int |
the amount of insets to remove from the right. Must be non-negative. |
bottom: @IntRange(from = 0) Int |
the amount of insets to remove from the bottom. Must be non-negative. |
| Returns | |
|---|---|
WindowInsetsCompat |
the inset insets |
isConsumed
fun isConsumed(): Boolean
Check if these insets have been fully consumed.
Insets are considered "consumed" if the applicable consume* methods have been called such that all insets have been set to zero. This affects propagation of insets through the view hierarchy; insets that have not been fully consumed will continue to propagate down to child views.
The result of this method is equivalent to the return value of fitSystemWindows.
| Returns | |
|---|---|
Boolean |
true if the insets have been fully consumed. |
isRound
fun isRound(): Boolean
Returns true if the associated window has a round shape.
A round window's left, top, right and bottom edges reach all the way to the associated edges of the window but the corners may not be visible. Views responding to round insets should take care to not lay out critical elements within the corners where they may not be accessible.
When running on platforms with API 19 and below, this method always returns false.
| Returns | |
|---|---|
Boolean |
true if the window is round |
isVisible
fun isVisible(typeMask: Int): Boolean
Returns whether a set of windows that may cause insets is currently visible on screen, regardless of whether it actually overlaps with this window. When running on devices with API Level 29 and before, the returned value is an approximation based on the information available. This is especially true for the IME type, which currently only works when running on devices with SDK level 23 and above.
| Returns | |
|---|---|
Boolean |
|
funreplaceSystemWindowInsets(systemWindowInsets: Rect): WindowInsetsCompat
Returns a copy of this WindowInsets with selected system window insets replaced with new values.
When running on platforms with API 19 and below, this method always returns null.
| Parameters | |
|---|---|
systemWindowInsets: Rect |
New system window insets. Each field is the inset in pixels for that edge |
| Returns | |
|---|---|
WindowInsetsCompat |
A modified copy of this WindowInsets |
funreplaceSystemWindowInsets(left: Int, top: Int, right: Int, bottom: Int): WindowInsetsCompat
Returns a copy of this WindowInsets with selected system window insets replaced with new values.
When running on platforms with API 19 and below, this method always returns null.
| Parameters | |
|---|---|
left: Int |
New left inset in pixels |
top: Int |
New top inset in pixels |
right: Int |
New right inset in pixels |
bottom: Int |
New bottom inset in pixels |
| Returns | |
|---|---|
WindowInsetsCompat |
A modified copy of this WindowInsets |
toWindowInsets
@RequiresApi(value = 20)
fun toWindowInsets(): WindowInsets?
Return the source WindowInsets instance used in this WindowInsetsCompat.
| Returns | |
|---|---|
WindowInsets? |
the wrapped WindowInsets instance |
toWindowInsetsCompat
@RequiresApi(value = 20)
java-static fun toWindowInsetsCompat(insets: WindowInsets): WindowInsetsCompat
Wrap an instance of WindowInsets into a WindowInsetsCompat.
This version of the function does not allow the resulting WindowInsetsCompat to be aware of the root window insets and root view, meaning that the returned values for many of the different inset Types will be incorrect.
Prefer using toWindowInsetsCompat instead.
| Parameters | |
|---|---|
insets: WindowInsets |
source insets to wrap |
| Returns | |
|---|---|
WindowInsetsCompat |
the wrapped instance |
toWindowInsetsCompat
@RequiresApi(value = 20)
java-static fun toWindowInsetsCompat(insets: WindowInsets, view: View?): WindowInsetsCompat
Wrap an instance of WindowInsets into a WindowInsetsCompat.
This version of the function allows the resulting WindowInsetsCompat to be aware of the root window insets and root view through the view parameter. This is required for many of the different inset Types to return correct values when used on devices running Android 10 and before.
| Parameters | |
|---|---|
insets: WindowInsets |
source insets to wrap |
view: View? |
view to use as an entry point for obtaining root window information. This view needs be attached to the window, otherwise it will be ignored. |
| Returns | |
|---|---|
WindowInsetsCompat |
the wrapped instance |