Added in API level 29

Builder

class Builder
kotlin.Any
   ↳ android.view.WindowInsets.Builder

Builder for WindowInsets.

Summary

Public constructors

Creates a builder where all insets are initially consumed.

Creates a builder where all insets are initialized from WindowInsets.

Public methods
WindowInsets

Builds a WindowInsets instance.

WindowInsets.Builder

Sets the display cutout.

WindowInsets.Builder

Sets the display shape.

WindowInsets.Builder
setInsets(typeMask: Int, insets: Insets)

Sets the insets of a specific window type in pixels.

WindowInsets.Builder
setInsetsIgnoringVisibility(typeMask: Int, insets: Insets)

Sets the insets a specific window type in pixels, while ignoring its visibility state.

WindowInsets.Builder

Sets mandatory system gesture insets in pixels.

WindowInsets.Builder

Sets the bounds of the system privacy indicator.

WindowInsets.Builder
setRoundedCorner(position: Int, roundedCorner: RoundedCorner?)

Sets the rounded corner of given position.

WindowInsets.Builder
setStableInsets(stableInsets: Insets)

Sets the stable insets in pixels.

WindowInsets.Builder

Sets system gesture insets in pixels.

WindowInsets.Builder
setSystemWindowInsets(systemWindowInsets: Insets)

Sets system window insets in pixels.

WindowInsets.Builder

Sets tappable element insets in pixels.

WindowInsets.Builder
setVisible(typeMask: Int, visible: Boolean)

Sets whether windows that can cause insets are currently visible on screen.

Public constructors

Builder

Added in API level 29
Builder()

Creates a builder where all insets are initially consumed.

Builder

Added in API level 29
Builder(insets: WindowInsets)

Creates a builder where all insets are initialized from WindowInsets.

Parameters
insets WindowInsets: the instance to initialize from. This value cannot be null.

Public methods

build

Added in API level 29
fun build(): WindowInsets

Builds a WindowInsets instance.

Return
WindowInsets the WindowInsets instance. This value cannot be null.

setDisplayCutout

Added in API level 29
fun setDisplayCutout(displayCutout: DisplayCutout?): WindowInsets.Builder

Sets the display cutout.

Parameters
displayCutout DisplayCutout?: the display cutout or null if there is none
Return
WindowInsets.Builder itself This value cannot be null.

setDisplayShape

Added in API level 34
fun setDisplayShape(displayShape: DisplayShape): WindowInsets.Builder

Sets the display shape.

Parameters
displayShape DisplayShape: the display shape. This value cannot be null.
Return
WindowInsets.Builder itself. This value cannot be null.

setInsets

Added in API level 30
fun setInsets(
    typeMask: Int,
    insets: Insets
): WindowInsets.Builder

Sets the insets of a specific window type in pixels.

The insets represents the area of a a window that is partially or fully obscured by the system windows identified by typeMask.

Parameters
typeMask Int: The bitmask of Type to set the insets for. Value is either 0 or a combination of android.view.WindowInsets.Type.STATUS_BARS, android.view.WindowInsets.Type.NAVIGATION_BARS, android.view.WindowInsets.Type.CAPTION_BAR, android.view.WindowInsets.Type.IME, android.view.WindowInsets.Type.WINDOW_DECOR, android.view.WindowInsets.Type.SYSTEM_GESTURES, android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES, android.view.WindowInsets.Type.TAPPABLE_ELEMENT, android.view.WindowInsets.Type.DISPLAY_CUTOUT, and android.view.WindowInsets.Type.SYSTEM_OVERLAYS
insets Insets: The insets to set. This value cannot be null.
Return
WindowInsets.Builder itself This value cannot be null.

See Also

setInsetsIgnoringVisibility

Added in API level 30
fun setInsetsIgnoringVisibility(
    typeMask: Int,
    insets: Insets
): WindowInsets.Builder

Sets the insets a specific window type in pixels, while ignoring its visibility state.

The insets represents the area of a a window that that may be partially or fully obscured by the system window identified by type. 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.

Parameters
typeMask Int: The bitmask of Type to set the insets for. Value is either 0 or a combination of android.view.WindowInsets.Type.STATUS_BARS, android.view.WindowInsets.Type.NAVIGATION_BARS, android.view.WindowInsets.Type.CAPTION_BAR, android.view.WindowInsets.Type.IME, android.view.WindowInsets.Type.WINDOW_DECOR, android.view.WindowInsets.Type.SYSTEM_GESTURES, android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES, android.view.WindowInsets.Type.TAPPABLE_ELEMENT, android.view.WindowInsets.Type.DISPLAY_CUTOUT, and android.view.WindowInsets.Type.SYSTEM_OVERLAYS
insets Insets: The insets to set. This value cannot be null.
Return
WindowInsets.Builder itself This value cannot be null.
Exceptions
java.lang.IllegalArgumentException If typeMask contains Type#ime(). Maximum insets are not available for this type 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.

setMandatorySystemGestureInsets

Added in API level 29
Deprecated in API level 30
fun setMandatorySystemGestureInsets(insets: Insets): WindowInsets.Builder

Deprecated: Use setInsets(int,android.graphics.Insets) with Type#mandatorySystemGestures().

Sets mandatory system gesture insets in pixels.

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.

In contrast to regular system gestures, mandatory system gestures cannot be overriden by View#setSystemGestureExclusionRects.

Parameters
insets Insets: This value cannot be null.
Return
WindowInsets.Builder itself This value cannot be null.

setPrivacyIndicatorBounds

Added in API level 31
fun setPrivacyIndicatorBounds(bounds: Rect?): WindowInsets.Builder

Sets the bounds of the system privacy indicator.

Parameters
bounds Rect?: The bounds of the system privacy indicator This value may be null.
Return
WindowInsets.Builder This value cannot be null.

setRoundedCorner

Added in API level 31
fun setRoundedCorner(
    position: Int,
    roundedCorner: RoundedCorner?
): WindowInsets.Builder

Sets the rounded corner of given position.

Parameters
position Int: the position of this rounded corner Value is android.view.RoundedCorner#POSITION_TOP_LEFT, android.view.RoundedCorner#POSITION_TOP_RIGHT, android.view.RoundedCorner#POSITION_BOTTOM_RIGHT, or android.view.RoundedCorner#POSITION_BOTTOM_LEFT
roundedCorner RoundedCorner?: the rounded corner or null if there is none
Return
WindowInsets.Builder itself This value cannot be null.

setStableInsets

Added in API level 29
Deprecated in API level 30
fun setStableInsets(stableInsets: Insets): WindowInsets.Builder

Deprecated: Use setInsetsIgnoringVisibility(int,android.graphics.Insets) with Type#systemBars().

Sets 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.

Parameters
stableInsets Insets: This value cannot be null.
Return
WindowInsets.Builder itself This value cannot be null.

setSystemGestureInsets

Added in API level 29
Deprecated in API level 30
fun setSystemGestureInsets(insets: Insets): WindowInsets.Builder

Deprecated: Use setInsets(int,android.graphics.Insets) with Type#systemGestures().

Sets system gesture insets in pixels.

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.

Parameters
insets Insets: This value cannot be null.
Return
WindowInsets.Builder itself This value cannot be null.

setSystemWindowInsets

Added in API level 29
Deprecated in API level 30
fun setSystemWindowInsets(systemWindowInsets: Insets): WindowInsets.Builder

Deprecated: Use setInsets(int,android.graphics.Insets) with Type#systemBars().

Sets 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.

Parameters
systemWindowInsets Insets: This value cannot be null.
Return
WindowInsets.Builder itself This value cannot be null.

setTappableElementInsets

Added in API level 29
Deprecated in API level 30
fun setTappableElementInsets(insets: Insets): WindowInsets.Builder

Deprecated: Use setInsets(int,android.graphics.Insets) with Type#tappableElement().

Sets tappable element insets in pixels.

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.

Parameters
insets Insets: This value cannot be null.
Return
WindowInsets.Builder itself This value cannot be null.

setVisible

Added in API level 30
fun setVisible(
    typeMask: Int,
    visible: Boolean
): WindowInsets.Builder

Sets whether windows that can cause insets are currently visible on screen.

Parameters
typeMask Int: The bitmask of Type to set the visibility for. Value is either 0 or a combination of android.view.WindowInsets.Type.STATUS_BARS, android.view.WindowInsets.Type.NAVIGATION_BARS, android.view.WindowInsets.Type.CAPTION_BAR, android.view.WindowInsets.Type.IME, android.view.WindowInsets.Type.WINDOW_DECOR, android.view.WindowInsets.Type.SYSTEM_GESTURES, android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES, android.view.WindowInsets.Type.TAPPABLE_ELEMENT, android.view.WindowInsets.Type.DISPLAY_CUTOUT, and android.view.WindowInsets.Type.SYSTEM_OVERLAYS
visible Boolean: Whether to mark the windows as visible or not.
Return
WindowInsets.Builder itself This value cannot be null.

See Also