{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public final class WindowInsetsKt
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 } } } }
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 } } } }
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.
@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 } } } }
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 } } } }
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
.
@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.
@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.
@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.
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getCaptionBar(@NonNull WindowInsets.Companion receiver)
For the WindowInsetsCompat.Type.captionBar
.
@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.
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.
@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.
@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
.
@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.
@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.
@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.
@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.
@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.
@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
.
@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
.
@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
.
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getStatusBars(@NonNull WindowInsets.Companion receiver)
For the WindowInsetsCompat.Type.statusBars
.
@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.
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getSystemBars(@NonNull WindowInsets.Companion receiver)
For the WindowInsetsCompat.Type.systemBars
.
@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.
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getSystemGestures(@NonNull WindowInsets.Companion receiver)
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getTappableElement(@NonNull WindowInsets.Companion receiver)
@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.
@Composable
@NonRestartableComposable
public static final @NonNull WindowInsets getWaterfall(@NonNull WindowInsets.Companion receiver)
The insets for the curved areas in a waterfall display.
@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.
@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.
@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.
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
.
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.
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
.