{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

WindowInsetsKt

public final class WindowInsetsKt


Summary

Public methods

static final @NonNull WindowInsets
WindowInsets(
    @NonNull Dp left,
    @NonNull Dp top,
    @NonNull Dp right,
    @NonNull Dp bottom
)

Create a WindowInsets with fixed dimensions, using Dp values.

static final @NonNull WindowInsets
WindowInsets(int left, int top, int right, int bottom)

Create a WindowInsets with fixed dimensions.

static final @NonNull WindowInsets

Returns a WindowInsets that has values of this, added to the values of insets.

static final @NonNull PaddingValues

Convert a WindowInsets to a PaddingValues and uses LocalDensity for DP to pixel conversion.

static final @NonNull PaddingValues

Convert a WindowInsets to a PaddingValues and uses density for DP to pixel conversion.

static final @NonNull WindowInsets

Returns the values in this WindowInsets that are not also in insets.

static final boolean

true when the navigationBars are being displayed, irrespective of whether they intersects with the Window.

static final boolean

true when the statusBars are being displayed, irrespective of whether they intersects with the Window.

static final boolean

true when the systemBars are being displayed, irrespective of whether they intersects with the Window.

static final @NonNull WindowInsets

For the WindowInsetsCompat.Type.captionBar.

static final @NonNull WindowInsets

The insets that the WindowInsetsCompat.Type.captionBar will consume if shown.

static final boolean

Indicates whether access to WindowInsets within the content should consume the Android android.view.WindowInsets.

static final @NonNull WindowInsets

For the WindowInsetsCompat.Type.displayCutout.

static final @NonNull WindowInsets

For the WindowInsetsCompat.Type.ime.

static final @NonNull WindowInsets

The WindowInsets for the IME before the IME started animating in.

static final @NonNull WindowInsets

The WindowInsets for the IME when the animation completes, if it is allowed to complete successfully.

static final @NonNull WindowInsets

For the WindowInsetsCompat.Type.mandatorySystemGestures.

static final @NonNull WindowInsets

For the WindowInsetsCompat.Type.navigationBars.

static final @NonNull WindowInsets

The insets that WindowInsetsCompat.Type.navigationBars will consume if shown.

static final @NonNull WindowInsets

The insets that include all areas that may be drawn over or have gesture confusion, including everything in safeDrawing and safeGestures.

static final @NonNull WindowInsets

The insets that include areas where content may be covered by other drawn content.

static final @NonNull WindowInsets

The insets that include areas where gestures may be confused with other input, including system gestures, mandatory system gestures, rounded display areas, and tappable areas.

static final @NonNull WindowInsets

For the WindowInsetsCompat.Type.statusBars.

static final @NonNull WindowInsets

The insets that WindowInsetsCompat.Type.statusBars will consume if shown.

static final @NonNull WindowInsets

For the WindowInsetsCompat.Type.systemBars.

static final @NonNull WindowInsets

The insets that WindowInsetsCompat.Type.systemBars will consume if shown.

static final @NonNull WindowInsets

For the WindowInsetsCompat.Type.systemGestures.

static final @NonNull WindowInsets

For the WindowInsetsCompat.Type.tappableElement.

static final @NonNull WindowInsets

The insets that WindowInsetsCompat.Type.tappableElement will consume if active.

static final @NonNull WindowInsets

The insets for the curved areas in a waterfall display.

static final boolean

true when the caption bar is being displayed, irrespective of whether it intersects with the Window.

static final boolean

true when the soft keyboard is being displayed, irrespective of whether it intersects with the Window.

static final boolean

true when the tappableElement is being displayed, irrespective of whether they intersects with the Window.

static final @NonNull WindowInsets

Returns a WindowInsets that eliminates all dimensions except the ones that are enabled.

static final void
setConsumeWindowInsets(
    @NonNull ComposeView receiver,
    boolean consumeWindowInsets
)

Indicates whether access to WindowInsets within the content should consume the Android android.view.WindowInsets.

static final @NonNull WindowInsets

Returns a WindowInsets that has the maximum values of this WindowInsets and insets.

Public methods

WindowInsets

public static final @NonNull WindowInsets WindowInsets(
    @NonNull Dp left,
    @NonNull Dp top,
    @NonNull Dp right,
    @NonNull Dp bottom
)

Create a WindowInsets with fixed dimensions, using Dp values.

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            // Make sure we are at least 10 DP away from the top.
            val insets = WindowInsets.statusBars.union(WindowInsets(top = 10.dp))
            Box(Modifier.windowInsetsPadding(insets)) {
                // app content
            }
        }
    }
}

WindowInsets

public static final @NonNull WindowInsets WindowInsets(int left, int top, int right, int bottom)

Create a WindowInsets with fixed dimensions.

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            // Make sure we are at least 10 pixels away from the top.
            val insets = WindowInsets.statusBars.union(WindowInsets(top = 10))
            Box(Modifier.windowInsetsPadding(insets)) {
                // app content
            }
        }
    }
}

add

public static final @NonNull WindowInsets add(@NonNull WindowInsets receiver, @NonNull WindowInsets insets)

Returns a WindowInsets that has values of this, added to the values of insets. For example, if this has a top of 10 and insets has a top of 5, the returned WindowInsets will have a top of 15.

asPaddingValues

@Composable
public static final @NonNull PaddingValues asPaddingValues(@NonNull WindowInsets receiver)

Convert a WindowInsets to a PaddingValues and uses LocalDensity for DP to pixel conversion. PaddingValues can be passed to some containers to pad internal content so that it doesn't overlap the insets when fully scrolled. Ensure that the insets are consumed after the padding is applied if insets are to be used further down the hierarchy.

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.lazy.LazyColumn
import androidx.core.view.WindowCompat

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            LazyColumn(
                contentPadding = WindowInsets.navigationBars.asPaddingValues()
            ) {
                // items
            }
        }
    }
}

asPaddingValues

public static final @NonNull PaddingValues asPaddingValues(@NonNull WindowInsets receiver, @NonNull Density density)

Convert a WindowInsets to a PaddingValues and uses density for DP to pixel conversion. PaddingValues can be passed to some containers to pad internal content so that it doesn't overlap the insets when fully scrolled. Ensure that the insets are consumed after the padding is applied if insets are to be used further down the hierarchy.

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.lazy.LazyColumn
import androidx.core.view.WindowCompat

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            LazyColumn(
                contentPadding = WindowInsets.navigationBars.asPaddingValues()
            ) {
                // items
            }
        }
    }
}

exclude

public static final @NonNull WindowInsets exclude(@NonNull WindowInsets receiver, @NonNull WindowInsets insets)

Returns the values in this WindowInsets that are not also in insets. For example, if this WindowInsets has a WindowInsets.getTop value of 10 and insets has a WindowInsets.getTop value of 8, the returned WindowInsets will have a WindowInsets.getTop value of 2.

Negative values are never returned. For example if insets has a WindowInsets.getTop of 10 and this has a WindowInsets.getTop of 0, the returned WindowInsets will have a WindowInsets.getTop value of 0.

getAreNavigationBarsVisible

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final boolean getAreNavigationBarsVisible(@NonNull WindowInsets.Companion receiver)

true when the navigationBars are being displayed, irrespective of whether they intersects with the Window.

getAreStatusBarsVisible

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final boolean getAreStatusBarsVisible(@NonNull WindowInsets.Companion receiver)

true when the statusBars are being displayed, irrespective of whether they intersects with the Window.

getAreSystemBarsVisible

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final boolean getAreSystemBarsVisible(@NonNull WindowInsets.Companion receiver)

true when the systemBars are being displayed, irrespective of whether they intersects with the Window.

getCaptionBar

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getCaptionBar(@NonNull WindowInsets.Companion receiver)

For the WindowInsetsCompat.Type.captionBar.

getCaptionBarIgnoringVisibility

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getCaptionBarIgnoringVisibility(
    @NonNull WindowInsets.Companion receiver
)

The insets that the WindowInsetsCompat.Type.captionBar will consume if shown. If it cannot be shown then this will be empty.

getConsumeWindowInsets

public static final boolean getConsumeWindowInsets(@NonNull ComposeView receiver)

Indicates whether access to WindowInsets within the content should consume the Android android.view.WindowInsets. The default value is true, meaning that access to WindowInsets.Companion will consume the Android WindowInsets.

This property should be set prior to first composition.

getDisplayCutout

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getDisplayCutout(@NonNull WindowInsets.Companion receiver)

For the WindowInsetsCompat.Type.displayCutout. This insets represents the area that the display cutout (e.g. for camera) is and important content should be excluded from.

getIme

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getIme(@NonNull WindowInsets.Companion receiver)

For the WindowInsetsCompat.Type.ime. On API level 23 (M) and above, the soft keyboard can be detected and ime will update when it shows. On API 30 (R) and above, the ime insets will animate synchronously with the actual IME animation.

Developers should set android:windowSoftInputMode="adjustResize" in their AndroidManifest.xml file and call WindowCompat.setDecorFitsSystemWindows(window, false) in their android.app.Activity.onCreate.

getImeAnimationSource

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getImeAnimationSource(@NonNull WindowInsets.Companion receiver)

The WindowInsets for the IME before the IME started animating in. The current animated value is WindowInsets.Companion.ime.

This will be the same as imeAnimationTarget when there is no IME animation in progress.

getImeAnimationTarget

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getImeAnimationTarget(@NonNull WindowInsets.Companion receiver)

The WindowInsets for the IME when the animation completes, if it is allowed to complete successfully. The current animated value is WindowInsets.Companion.ime.

This will be the same as imeAnimationSource when there is no IME animation in progress.

getMandatorySystemGestures

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getMandatorySystemGestures(@NonNull WindowInsets.Companion receiver)

For the WindowInsetsCompat.Type.mandatorySystemGestures. These insets represents the space where system gestures have priority over application gestures.

getNavigationBars

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getNavigationBars(@NonNull WindowInsets.Companion receiver)

For the WindowInsetsCompat.Type.navigationBars. These insets represent where system UI places navigation bars. Interactive UI should avoid the navigation bars area.

getNavigationBarsIgnoringVisibility

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getNavigationBarsIgnoringVisibility(
    @NonNull WindowInsets.Companion receiver
)

The insets that WindowInsetsCompat.Type.navigationBars will consume if shown. These insets represent where system UI places navigation bars. Interactive UI should avoid the navigation bars area. If navigation bars cannot be shown, then this will be empty.

getSafeContent

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getSafeContent(@NonNull WindowInsets.Companion receiver)

The insets that include all areas that may be drawn over or have gesture confusion, including everything in safeDrawing and safeGestures.

getSafeDrawing

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getSafeDrawing(@NonNull WindowInsets.Companion receiver)

The insets that include areas where content may be covered by other drawn content. This includes all system bars, display cutout, and soft keyboard.

getSafeGestures

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getSafeGestures(@NonNull WindowInsets.Companion receiver)

The insets that include areas where gestures may be confused with other input, including system gestures, mandatory system gestures, rounded display areas, and tappable areas.

getStatusBars

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getStatusBars(@NonNull WindowInsets.Companion receiver)

For the WindowInsetsCompat.Type.statusBars.

getStatusBarsIgnoringVisibility

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getStatusBarsIgnoringVisibility(
    @NonNull WindowInsets.Companion receiver
)

The insets that WindowInsetsCompat.Type.statusBars will consume if shown. If the status bar can never be shown, then this will be empty.

getSystemBars

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getSystemBars(@NonNull WindowInsets.Companion receiver)

For the WindowInsetsCompat.Type.systemBars.

getSystemBarsIgnoringVisibility

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getSystemBarsIgnoringVisibility(
    @NonNull WindowInsets.Companion receiver
)

The insets that WindowInsetsCompat.Type.systemBars will consume if shown.

If system bars can never be shown, then this will be empty.

getSystemGestures

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getSystemGestures(@NonNull WindowInsets.Companion receiver)

For the WindowInsetsCompat.Type.systemGestures.

getTappableElement

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getTappableElement(@NonNull WindowInsets.Companion receiver)

For the WindowInsetsCompat.Type.tappableElement.

getTappableElementIgnoringVisibility

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getTappableElementIgnoringVisibility(
    @NonNull WindowInsets.Companion receiver
)

The insets that WindowInsetsCompat.Type.tappableElement will consume if active.

If there are never tappable elements then this is empty.

getWaterfall

@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getWaterfall(@NonNull WindowInsets.Companion receiver)

The insets for the curved areas in a waterfall display.

isCaptionBarVisible

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final boolean isCaptionBarVisible(@NonNull WindowInsets.Companion receiver)

true when the caption bar is being displayed, irrespective of whether it intersects with the Window.

isImeVisible

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final boolean isImeVisible(@NonNull WindowInsets.Companion receiver)

true when the soft keyboard is being displayed, irrespective of whether it intersects with the Window.

isTappableElementVisible

@ExperimentalLayoutApi
@Composable
@NonRestartableComposable
public static final boolean isTappableElementVisible(@NonNull WindowInsets.Companion receiver)

true when the tappableElement is being displayed, irrespective of whether they intersects with the Window.

only

public static final @NonNull WindowInsets only(@NonNull WindowInsets receiver, @NonNull WindowInsetsSides sides)

Returns a WindowInsets that eliminates all dimensions except the ones that are enabled. For example, to have a WindowInsets at the bottom of the screen, pass WindowInsetsSides.Bottom.

setConsumeWindowInsets

public static final void setConsumeWindowInsets(
    @NonNull ComposeView receiver,
    boolean consumeWindowInsets
)

Indicates whether access to WindowInsets within the content should consume the Android android.view.WindowInsets. The default value is true, meaning that access to WindowInsets.Companion will consume the Android WindowInsets.

This property should be set prior to first composition.

union

public static final @NonNull WindowInsets union(@NonNull WindowInsets receiver, @NonNull WindowInsets insets)

Returns a WindowInsets that has the maximum values of this WindowInsets and insets.