WindowInsets.Builder


public static final class WindowInsets.Builder
extends Object

java.lang.Object
   ↳ android.view.WindowInsets.Builder


Builder for WindowInsets.

Summary

Public constructors

Builder()

Creates a builder where all insets are initially consumed.

Builder(WindowInsets insets)

Creates a builder where all insets are initialized from WindowInsets.

Public methods

WindowInsets build()

Builds a WindowInsets instance.

WindowInsets.Builder setBoundingRects(int typeMask, List<Rect> rects)

Sets the bounding rects.

WindowInsets.Builder setBoundingRectsIgnoringVisibility(int typeMask, List<Rect> rects)

Sets the bounding rects while ignoring their visibility state.

WindowInsets.Builder setDisplayCutout(DisplayCutout displayCutout)

Sets the display cutout.

WindowInsets.Builder setDisplayShape(DisplayShape displayShape)

Sets the display shape.

WindowInsets.Builder setFrame(int width, int height)

Set the frame size.

WindowInsets.Builder setInsets(int typeMask, Insets insets)

Sets the insets of a specific window type in pixels.

WindowInsets.Builder setInsetsIgnoringVisibility(int typeMask, Insets insets)

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

WindowInsets.Builder setMandatorySystemGestureInsets(Insets insets)

This method was deprecated in API level 30. Use setInsets(int, android.graphics.Insets) with Type#mandatorySystemGestures().

WindowInsets.Builder setPrivacyIndicatorBounds(Rect bounds)

Sets the bounds of the system privacy indicator.

WindowInsets.Builder setRoundedCorner(int position, RoundedCorner roundedCorner)

Sets the rounded corner of given position.

WindowInsets.Builder setStableInsets(Insets stableInsets)

This method was deprecated in API level 30. Use setInsetsIgnoringVisibility(int, android.graphics.Insets) with Type#systemBars().

WindowInsets.Builder setSystemGestureInsets(Insets insets)

This method was deprecated in API level 30. Use setInsets(int, android.graphics.Insets) with Type#systemGestures().

WindowInsets.Builder setSystemWindowInsets(Insets systemWindowInsets)

This method was deprecated in API level 30. Use setInsets(int, android.graphics.Insets) with Type#systemBars().

WindowInsets.Builder setTappableElementInsets(Insets insets)

This method was deprecated in API level 30. Use setInsets(int, android.graphics.Insets) with Type#tappableElement().

WindowInsets.Builder setVisible(int typeMask, boolean visible)

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

Inherited methods

Public constructors

Builder

Added in API level 29
public Builder ()

Creates a builder where all insets are initially consumed.

Builder

Added in API level 29
public Builder (WindowInsets insets)

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
public WindowInsets build ()

Builds a WindowInsets instance.

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

setBoundingRects

Added in API level 35
public WindowInsets.Builder setBoundingRects (int typeMask, 
                List<Rect> rects)

Sets the bounding rects.

Parameters
typeMask int: the inset types to which these rects apply. 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

rects List: the bounding rects. This value cannot be null.

Returns
WindowInsets.Builder itself. This value cannot be null.

setBoundingRectsIgnoringVisibility

Added in API level 35
public WindowInsets.Builder setBoundingRectsIgnoringVisibility (int typeMask, 
                List<Rect> rects)

Sets the bounding rects while ignoring their visibility state.

Parameters
typeMask int: the inset types to which these rects apply. 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

rects List: the bounding rects. This value cannot be null.

Returns
WindowInsets.Builder itself. This value cannot be null.

Throws
IllegalArgumentException If typeMask contains Type#ime(). Maximum bounding rects 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.

setDisplayCutout

Added in API level 29
public WindowInsets.Builder setDisplayCutout (DisplayCutout displayCutout)

Sets the display cutout.

Parameters
displayCutout DisplayCutout: the display cutout or null if there is none

Returns
WindowInsets.Builder itself This value cannot be null.

setDisplayShape

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

Sets the display shape.

Parameters
displayShape DisplayShape: the display shape. This value cannot be null.

Returns
WindowInsets.Builder itself. This value cannot be null.

setFrame

Added in API level 35
public WindowInsets.Builder setFrame (int width, 
                int height)

Set the frame size.

Parameters
width int: the width of the frame.

height int: the height of the frame.

Returns
WindowInsets.Builder itself. This value cannot be null.

setInsets

Added in API level 30
public WindowInsets.Builder setInsets (int typeMask, 
                Insets insets)

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.

Returns
WindowInsets.Builder itself This value cannot be null.

setInsetsIgnoringVisibility

Added in API level 30
public WindowInsets.Builder setInsetsIgnoringVisibility (int typeMask, 
                Insets insets)

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.

Returns
WindowInsets.Builder itself This value cannot be null.

Throws
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
public WindowInsets.Builder setMandatorySystemGestureInsets (Insets insets)

This method was deprecated in API level 30.
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.

Returns
WindowInsets.Builder itself This value cannot be null.

setPrivacyIndicatorBounds

Added in API level 31
public WindowInsets.Builder setPrivacyIndicatorBounds (Rect bounds)

Sets the bounds of the system privacy indicator.

Parameters
bounds Rect: The bounds of the system privacy indicator This value may be null.

Returns
WindowInsets.Builder This value cannot be null.

setRoundedCorner

Added in API level 31
public WindowInsets.Builder setRoundedCorner (int position, 
                RoundedCorner roundedCorner)

Sets the rounded corner of given position.

Parameters
position int: the position of this rounded corner Value is RoundedCorner.POSITION_TOP_LEFT, RoundedCorner.POSITION_TOP_RIGHT, RoundedCorner.POSITION_BOTTOM_RIGHT, or RoundedCorner.POSITION_BOTTOM_LEFT

roundedCorner RoundedCorner: the rounded corner or null if there is none

Returns
WindowInsets.Builder itself This value cannot be null.

setStableInsets

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

This method was deprecated in API level 30.
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.

Returns
WindowInsets.Builder itself This value cannot be null.

setSystemGestureInsets

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

This method was deprecated in API level 30.
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.

Returns
WindowInsets.Builder itself This value cannot be null.

setSystemWindowInsets

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

This method was deprecated in API level 30.
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.

Returns
WindowInsets.Builder itself This value cannot be null.

setTappableElementInsets

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

This method was deprecated in API level 30.
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.

Returns
WindowInsets.Builder itself This value cannot be null.

setVisible

Added in API level 30
public WindowInsets.Builder setVisible (int typeMask, 
                boolean visible)

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.

Returns
WindowInsets.Builder itself This value cannot be null.