-
public class WindowInsetsCompatDescribes 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classWindowInsetsCompat.BuilderBuilder for WindowInsetsCompat.
public final classWindowInsetsCompat.TypeClass that defines different types of sources causing window insets.
-
Field Summary
Fields Modifier and Type Field Description public final static WindowInsetsCompatCONSUMED
-
Constructor Summary
Constructors Constructor Description WindowInsetsCompat(WindowInsetsCompat src)Constructs a new WindowInsetsCompat, copying all values from a source WindowInsetsCompat.
-
Method Summary
Modifier and Type Method Description static WindowInsetsCompattoWindowInsetsCompat(@NonNull() WindowInsets insets)Wrap an instance of WindowInsets into a WindowInsetsCompat. static WindowInsetsCompattoWindowInsetsCompat(@NonNull() WindowInsets insets, @Nullable() View view)Wrap an instance of WindowInsets into a WindowInsetsCompat. intgetSystemWindowInsetLeft()Returns the left system window inset in pixels. intgetSystemWindowInsetTop()Returns the top system window inset in pixels. intgetSystemWindowInsetRight()Returns the right system window inset in pixels. intgetSystemWindowInsetBottom()Returns the bottom system window inset in pixels. booleanhasSystemWindowInsets()Returns true if this WindowInsets has nonzero system window insets. booleanhasInsets()Returns true if this WindowInsets has any non-zero insets. booleanisConsumed()Check if these insets have been fully consumed. booleanisRound()Returns true if the associated window has a round shape. WindowInsetsCompatconsumeSystemWindowInsets()Returns a copy of this WindowInsets with the system window insets fully consumed. WindowInsetsCompatreplaceSystemWindowInsets(int left, int top, int right, int bottom)Returns a copy of this WindowInsets with selected system window insets replacedwith new values. WindowInsetsCompatreplaceSystemWindowInsets(@NonNull() Rect systemWindowInsets)Returns a copy of this WindowInsets with selected system window insets replacedwith new values. intgetStableInsetTop()Returns the top stable inset in pixels. intgetStableInsetLeft()Returns the left stable inset in pixels. intgetStableInsetRight()Returns the right stable inset in pixels. intgetStableInsetBottom()Returns the bottom stable inset in pixels. booleanhasStableInsets()Returns true if this WindowInsets has nonzero stable insets. WindowInsetsCompatconsumeStableInsets()Returns a copy of this WindowInsets with the stable insets fully consumed. DisplayCutoutCompatgetDisplayCutout()Returns the display cutout if there is one. WindowInsetsCompatconsumeDisplayCutout()Returns a copy of this WindowInsets with the cutout fully consumed. InsetsgetSystemWindowInsets()Returns the system window insets in pixels. InsetsgetStableInsets()Returns the stable insets in pixels. InsetsgetMandatorySystemGestureInsets()Returns the mandatory system gesture insets. InsetsgetTappableElementInsets()Returns the tappable element insets. InsetsgetSystemGestureInsets()Returns the system gesture insets. WindowInsetsCompatinset(@NonNull() Insets insets)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 thecurrent area. WindowInsetsCompatinset(int left, int top, int right, int bottom)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 thecurrent area. InsetsgetInsets(int typeMask)Returns the insets of a specific set of windows causing insets, denoted by the {@code typeMask}bit mask of Types.When running on devices with API Level 29 and before, the returned insets are anapproximation based on the information available.InsetsgetInsetsIgnoringVisibility(int typeMask)Returns the insets a specific set of windows can cause, denoted by the {@code typeMask}bit mask of Types, regardless of whether that type iscurrently visible or not.booleanisVisible(int typeMask)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 anapproximation based on the information available. booleanequals(Object o)inthashCode()WindowInsetstoWindowInsets()Return the source WindowInsets instance used in this WindowInsetsCompat. -
-
Constructor Detail
-
WindowInsetsCompat
WindowInsetsCompat(WindowInsetsCompat src)
Constructs a new WindowInsetsCompat, copying all values from a source WindowInsetsCompat.- Parameters:
src- source from which values are copied
-
-
Method Detail
-
toWindowInsetsCompat
@NonNull() static WindowInsetsCompat toWindowInsetsCompat(@NonNull() WindowInsets insets)
Wrap an instance of WindowInsets into a WindowInsetsCompat.
This version of the function does not allow the resulting WindowInsetsCompat to beaware of the root window insets and root view, meaning that the returned values for many ofthe different inset Types will be incorrect.
Prefer using toWindowInsetsCompat instead.
- Parameters:
insets- source insets to wrap
-
toWindowInsetsCompat
@NonNull() static WindowInsetsCompat toWindowInsetsCompat(@NonNull() WindowInsets insets, @Nullable() View view)
Wrap an instance of WindowInsets into a WindowInsetsCompat.
This version of the function allows the resulting WindowInsetsCompat to beaware of the root window insets and root view through the
{@code view}parameter. This isrequired for many of the different inset Types to return correct values when usedon devices running Android 10 and before.- Parameters:
insets- source insets to wrapview- view to use as an entry point for obtaining root window information.
-
getSystemWindowInsetLeft
@Deprecated() int getSystemWindowInsetLeft()
Returns the left system window inset in pixels.
The system window inset represents the area of a full-screen window that ispartially 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
{@code 0}.
-
getSystemWindowInsetTop
@Deprecated() int getSystemWindowInsetTop()
Returns the top system window inset in pixels.
The system window inset represents the area of a full-screen window that ispartially 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
{@code 0}.
-
getSystemWindowInsetRight
@Deprecated() int getSystemWindowInsetRight()
Returns the right system window inset in pixels.
The system window inset represents the area of a full-screen window that ispartially 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
{@code 0}.
-
getSystemWindowInsetBottom
@Deprecated() int getSystemWindowInsetBottom()
Returns the bottom system window inset in pixels.
The system window inset represents the area of a full-screen window that ispartially 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
{@code 0}.
-
hasSystemWindowInsets
@Deprecated() boolean hasSystemWindowInsets()
Returns true if this WindowInsets has nonzero system window insets.
The system window inset represents the area of a full-screen window that ispartially 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
{@code false}.
-
hasInsets
boolean hasInsets()
Returns true if this WindowInsets has any non-zero insets.
When running on platforms with API 19 and below, this method always returns
{@code false}.
-
isConsumed
boolean isConsumed()
Check if these insets have been fully consumed.
Insets are considered "consumed" if the applicable
consume*methodshave been called such that all insets have been set to zero. This affects propagation ofinsets through the view hierarchy; insets that have not been fully consumed will continueto propagate down to child views.The result of this method is equivalent to the return value of fitSystemWindows.
-
isRound
boolean isRound()
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 theassociated edges of the window but the corners may not be visible. Views respondingto round insets should take care to not lay out critical elements within the cornerswhere they may not be accessible.
When running on platforms with API 19 and below, this method always returns
{@code false}.
-
consumeSystemWindowInsets
@Deprecated()@NonNull() WindowInsetsCompat consumeSystemWindowInsets()
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
{@code null}.
-
replaceSystemWindowInsets
@Deprecated()@NonNull() WindowInsetsCompat replaceSystemWindowInsets(int left, int top, int right, int bottom)
Returns a copy of this WindowInsets with selected system window insets replacedwith new values.
When running on platforms with API 19 and below, this method always returns
{@code null}.- Parameters:
left- New left inset in pixelstop- New top inset in pixelsright- New right inset in pixelsbottom- New bottom inset in pixels
-
replaceSystemWindowInsets
@Deprecated()@NonNull() WindowInsetsCompat replaceSystemWindowInsets(@NonNull() Rect systemWindowInsets)
Returns a copy of this WindowInsets with selected system window insets replacedwith new values.
When running on platforms with API 19 and below, this method always returns
{@code null}.- Parameters:
systemWindowInsets- New system window insets.
-
getStableInsetTop
@Deprecated() int getStableInsetTop()
Returns the top stable inset in pixels.
The stable inset represents the area of a full-screen window that may bepartially or fully obscured by the system UI elements. This value does not changebased on the visibility state of those elements; for example, if the status bar isnormally shown, but temporarily hidden, the stable inset will still provide the insetassociated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns
{@code 0}.
-
getStableInsetLeft
@Deprecated() int getStableInsetLeft()
Returns the left stable inset in pixels.
The stable inset represents the area of a full-screen window that may bepartially or fully obscured by the system UI elements. This value does not changebased on the visibility state of those elements; for example, if the status bar isnormally shown, but temporarily hidden, the stable inset will still provide the insetassociated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns
{@code 0}.
-
getStableInsetRight
@Deprecated() int getStableInsetRight()
Returns the right stable inset in pixels.
The stable inset represents the area of a full-screen window that may bepartially or fully obscured by the system UI elements. This value does not changebased on the visibility state of those elements; for example, if the status bar isnormally shown, but temporarily hidden, the stable inset will still provide the insetassociated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns
{@code 0}.
-
getStableInsetBottom
@Deprecated() int getStableInsetBottom()
Returns the bottom stable inset in pixels.
The stable inset represents the area of a full-screen window that may bepartially or fully obscured by the system UI elements. This value does not changebased on the visibility state of those elements; for example, if the status bar isnormally shown, but temporarily hidden, the stable inset will still provide the insetassociated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns
{@code 0}.
-
hasStableInsets
@Deprecated() boolean hasStableInsets()
Returns true if this WindowInsets has nonzero stable insets.
The stable inset represents the area of a full-screen window that may bepartially or fully obscured by the system UI elements. This value does not changebased on the visibility state of those elements; for example, if the status bar isnormally shown, but temporarily hidden, the stable inset will still provide the insetassociated with the status bar being shown.
When running on platforms with API 20 and below, this method always returns
{@code false}.
-
consumeStableInsets
@Deprecated()@NonNull() WindowInsetsCompat consumeStableInsets()
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
{@code null}.
-
getDisplayCutout
@Nullable() DisplayCutoutCompat getDisplayCutout()
Returns the display cutout if there is one.
When running on platforms with API 27 and below, this method always returns
{@code null}.
-
consumeDisplayCutout
@Deprecated()@NonNull() WindowInsetsCompat consumeDisplayCutout()
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.
-
getSystemWindowInsets
@Deprecated()@NonNull() Insets getSystemWindowInsets()
Returns the system window insets in pixels.
The system window inset represents the area of a full-screen window that ispartially or fully obscured by the status bar, navigation bar, IME or other system windows.
-
getStableInsets
@Deprecated()@NonNull() Insets getStableInsets()
Returns the stable insets in pixels.
The stable inset represents the area of a full-screen window that may bepartially or fully obscured by the system UI elements. This value does not changebased on the visibility state of those elements; for example, if the status bar isnormally shown, but temporarily hidden, the stable inset will still provide the insetassociated with the status bar being shown.
-
getMandatorySystemGestureInsets
@Deprecated()@NonNull() Insets getMandatorySystemGestureInsets()
Returns the mandatory system gesture insets.
The mandatory system gesture insets represent the area of a window where mandatory systemgestures have priority and may consume some or all touch input, e.g. due to the a system baroccupying it, or it being reserved for touch-only gestures.
-
getTappableElementInsets
@Deprecated()@NonNull() Insets getTappableElementInsets()
Returns the tappable element insets.
The tappable element insets represent how much tappable elements must at least beinset to remain both tappable and visually unobstructed by persistent system windows.
This may be smaller than getSystemWindowInsets if the system window islargely transparent and lets through simple taps (but not necessarily more complex gestures).
-
getSystemGestureInsets
@Deprecated()@NonNull() Insets getSystemGestureInsets()
Returns the system gesture insets.
The system gesture insets represent the area of a window where system gestures havepriority and may consume some or all touch input, e.g. due to the a system baroccupying 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.
-
inset
@NonNull() WindowInsetsCompat inset(@NonNull() Insets insets)
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 thecurrent area.
Example:
childView.dispatchApplyWindowInsets(insets.inset(childMargins));- Parameters:
insets- the amount of insets to remove from all sides.
-
inset
@NonNull() WindowInsetsCompat inset(int left, int top, int right, int bottom)
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 thecurrent area.
Example:
childView.dispatchApplyWindowInsets(insets.inset( childMarginLeft, childMarginTop, childMarginBottom, childMarginRight));- Parameters:
left- the amount of insets to remove from the left.top- the amount of insets to remove from the top.right- the amount of insets to remove from the right.bottom- the amount of insets to remove from the bottom.
-
getInsets
@NonNull() Insets getInsets(int typeMask)
Returns the insets of a specific set of windows causing insets, denoted by the
{@code typeMask}bit mask of Types.When running on devices with API Level 29 and before, the returned insets are anapproximation based on the information available. This is especially true for the IME type, which currently only works when running on devices with SDK level 23and above.- Parameters:
typeMask- Bit mask of Types to query the insets for.
-
getInsetsIgnoringVisibility
@NonNull() Insets getInsetsIgnoringVisibility(int typeMask)
Returns the insets a specific set of windows can cause, denoted by the
{@code typeMask}bit mask of Types, regardless of whether that type iscurrently visible or not.The insets represents the area of a a window that that may be partiallyor fully obscured by the system window identified by
When running on devices with API Level 29 and before, the returned insets are anapproximation based on the information available. This is especially true for the IME type, which currently only works when running on devices with SDK level 23and above.{@code typeMask}. This value does notchange based on the visibility state of those elements. For example, if the status bar isnormally shown, but temporarily hidden, the inset returned here will still provide the insetassociated with the status bar being shown.- Parameters:
typeMask- Bit mask of Types to query the insets for.
-
isVisible
boolean isVisible(int typeMask)
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 anapproximation based on the information available. This is especially true for the IME type, which currently only works when running on devices with SDK level 23and above.
- Parameters:
typeMask- Bit mask of Types to query visibility status.
-
hashCode
int hashCode()
-
toWindowInsets
@Nullable() WindowInsets toWindowInsets()
Return the source WindowInsets instance used in this WindowInsetsCompat.
-
-
-
-