WindowInsetsCompat

public class WindowInsetsCompat
extends Object

java.lang.Object
   ↳ androidx.core.view.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 classes

class WindowInsetsCompat.Builder

Builder for WindowInsetsCompat

class WindowInsetsCompat.Type

Class that defines different types of sources causing window insets. 

Fields

public static final WindowInsetsCompat CONSUMED

A WindowInsetsCompat instance for which isConsumed() returns true.

Public constructors

WindowInsetsCompat(WindowInsetsCompat src)

Constructs a new WindowInsetsCompat, copying all values from a source WindowInsetsCompat.

Public methods

WindowInsetsCompat consumeDisplayCutout()

This method is deprecated. Consuming of different parts individually of a WindowInsetsCompat instance is deprecated, since WindowInsetsCompat contains many different insets. Use CONSUMED instead to stop dispatching insets.

WindowInsetsCompat consumeStableInsets()

This method is deprecated. Consuming of different parts individually of a WindowInsetsCompat instance is deprecated, since WindowInsetsCompat contains many different insets. Use CONSUMED instead to stop dispatching insets.

WindowInsetsCompat consumeSystemWindowInsets()

This method is deprecated. Consuming of different parts individually of a WindowInsetsCompat instance is deprecated, since WindowInsetsCompat contains many different insets. Use CONSUMED instead to stop dispatching insets.

boolean equals(Object o)
DisplayCutoutCompat getDisplayCutout()

Returns the display cutout if there is one.

Insets getInsets(int typeMask)

Returns the insets of a specific set of windows causing insets, denoted by the typeMask bit mask of WindowInsetsCompat.Types.

Insets getInsetsIgnoringVisibility(int typeMask)

Returns the insets a specific set of windows can cause, denoted by the typeMask bit mask of WindowInsetsCompat.Types, regardless of whether that type is currently visible or not.

Insets getMandatorySystemGestureInsets()

This method is deprecated. Use getInsets(int) with WindowInsetsCompat.Type.mandatorySystemGestures() instead.

int getStableInsetBottom()

This method is deprecated. Use getInsetsIgnoringVisibility(int) with WindowInsetsCompat.Type.systemBars() instead.

int getStableInsetLeft()

This method is deprecated. Use getInsetsIgnoringVisibility(int) with WindowInsetsCompat.Type.systemBars() instead.

int getStableInsetRight()

This method is deprecated. Use getInsetsIgnoringVisibility(int) with WindowInsetsCompat.Type.systemBars() instead.

int getStableInsetTop()

This method is deprecated. Use getInsetsIgnoringVisibility(int) with WindowInsetsCompat.Type.systemBars() instead.

Insets getStableInsets()

This method is deprecated. Use getInsetsIgnoringVisibility(int) with WindowInsetsCompat.Type.systemBars() instead.

Insets getSystemGestureInsets()

This method is deprecated. Use getInsets(int) with WindowInsetsCompat.Type.systemGestures() instead.

int getSystemWindowInsetBottom()

This method is deprecated. Use getInsets(int) with WindowInsetsCompat.Type.systemBars() instead.

int getSystemWindowInsetLeft()

This method is deprecated. Use getInsets(int) with WindowInsetsCompat.Type.systemBars() instead.

int getSystemWindowInsetRight()

This method is deprecated. Use getInsets(int) with WindowInsetsCompat.Type.systemBars() instead.

int getSystemWindowInsetTop()

This method is deprecated. Use getInsets(int) with WindowInsetsCompat.Type.systemBars() instead.

Insets getSystemWindowInsets()

This method is deprecated. Use getInsets(int) with WindowInsetsCompat.Type.systemBars() instead.

Insets getTappableElementInsets()

This method is deprecated. Use getInsets(int) with WindowInsetsCompat.Type.tappableElement() instead.

boolean hasInsets()

Returns true if this WindowInsets has any non-zero insets.

boolean hasStableInsets()

This method is deprecated. Use getInsetsIgnoringVisibility(int) with WindowInsetsCompat.Type.systemBars() instead.

boolean hasSystemWindowInsets()

This method is deprecated. Use getInsets(int) with WindowInsetsCompat.Type.systemBars() instead.

int hashCode()
WindowInsetsCompat inset(int left, int top, int right, int bottom)

Returns a copy of this instance inset in the given directions.

WindowInsetsCompat inset(Insets insets)

Returns a copy of this instance inset in the given directions.

boolean isConsumed()

Check if these insets have been fully consumed.

boolean isRound()

Returns true if the associated window has a round shape.

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.

WindowInsetsCompat replaceSystemWindowInsets(int left, int top, int right, int bottom)

This method is deprecated. use WindowInsetsCompat.Builder with WindowInsetsCompat.Builder.setSystemWindowInsets(Insets) instead.

WindowInsetsCompat replaceSystemWindowInsets(Rect systemWindowInsets)

This method is deprecated. use WindowInsetsCompat.Builder with WindowInsetsCompat.Builder.setSystemWindowInsets(Insets) instead.

WindowInsets toWindowInsets()

Return the source WindowInsets instance used in this WindowInsetsCompat.

static WindowInsetsCompat toWindowInsetsCompat(WindowInsets insets)

Wrap an instance of WindowInsets into a WindowInsetsCompat.

static WindowInsetsCompat toWindowInsetsCompat(WindowInsets insets, View view)

Wrap an instance of WindowInsets into a WindowInsetsCompat.

Inherited methods

Fields

CONSUMED

public static final WindowInsetsCompat CONSUMED

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 OnApplyWindowInsetsListener.onApplyWindowInsets(View, WindowInsetsCompat) 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:

Public constructors

WindowInsetsCompat

public WindowInsetsCompat (WindowInsetsCompat src)

Constructs a new WindowInsetsCompat, copying all values from a source WindowInsetsCompat.

Parameters
src WindowInsetsCompat: source from which values are copied

Public methods

consumeDisplayCutout

public WindowInsetsCompat consumeDisplayCutout ()

This method is deprecated.
Consuming of different parts individually of a WindowInsetsCompat instance is deprecated, since WindowInsetsCompat contains many different insets. Use CONSUMED instead to stop dispatching insets.

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

consumeStableInsets

public WindowInsetsCompat consumeStableInsets ()

This method is deprecated.
Consuming of different parts individually of a WindowInsetsCompat instance is deprecated, since WindowInsetsCompat contains many different insets. Use CONSUMED instead to stop dispatching insets.

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

consumeSystemWindowInsets

public WindowInsetsCompat consumeSystemWindowInsets ()

This method is deprecated.
Consuming of different parts individually of a WindowInsetsCompat instance is deprecated, since WindowInsetsCompat contains many different insets. Use CONSUMED instead to stop dispatching insets.

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

equals

public boolean equals (Object o)

Parameters
o Object

Returns
boolean

getDisplayCutout

public DisplayCutoutCompat getDisplayCutout ()

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

getInsets

public Insets getInsets (int typeMask)

Returns the insets of a specific set of windows causing insets, denoted by the typeMask bit mask of WindowInsetsCompat.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.

Parameters
typeMask int: Bit mask of WindowInsetsCompat.Types to query the insets for.

Returns
Insets The insets.

getInsetsIgnoringVisibility

public Insets getInsetsIgnoringVisibility (int typeMask)

Returns the insets a specific set of windows can cause, denoted by the typeMask bit mask of WindowInsetsCompat.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.

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.

Parameters
typeMask int: Bit mask of WindowInsetsCompat.Types to query the insets for.

Returns
Insets The insets.

Throws
IllegalArgumentException If the caller tries to query WindowInsetsCompat.Type.ime(). Insets are not available if the IME isn't visible as the height of the IME is dynamic depending on the EditorInfo of the currently focused view, as well as the UI state of the IME.

getMandatorySystemGestureInsets

public Insets getMandatorySystemGestureInsets ()

This method is deprecated.
Use getInsets(int) with WindowInsetsCompat.Type.mandatorySystemGestures() instead.

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.

Returns
Insets

getStableInsetBottom

public int getStableInsetBottom ()

This method is deprecated.
Use getInsetsIgnoringVisibility(int) with WindowInsetsCompat.Type.systemBars() instead.

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

getStableInsetLeft

public int getStableInsetLeft ()

This method is deprecated.
Use getInsetsIgnoringVisibility(int) with WindowInsetsCompat.Type.systemBars() instead.

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

getStableInsetRight

public int getStableInsetRight ()

This method is deprecated.
Use getInsetsIgnoringVisibility(int) with WindowInsetsCompat.Type.systemBars() instead.

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

getStableInsetTop

public int getStableInsetTop ()

This method is deprecated.
Use getInsetsIgnoringVisibility(int)