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

WindowInsetsSizeKt

public final class WindowInsetsSizeKt


Summary

Public methods

static final @NonNull Modifier
windowInsetsBottomHeight(
    @NonNull Modifier receiver,
    @NonNull WindowInsets insets
)

Sets the height to that of insets at the bottom of the screen.

static final @NonNull Modifier
windowInsetsEndWidth(
    @NonNull Modifier receiver,
    @NonNull WindowInsets insets
)

Sets the width to that of insets at the end of the screen, using either left or right, depending on the LayoutDirection.

static final @NonNull Modifier
windowInsetsStartWidth(
    @NonNull Modifier receiver,
    @NonNull WindowInsets insets
)

Sets the width to that of insets at the start of the screen, using either left or right, depending on the LayoutDirection.

static final @NonNull Modifier
windowInsetsTopHeight(
    @NonNull Modifier receiver,
    @NonNull WindowInsets insets
)

Sets the height to that of insets at the top of the screen.

Public methods

windowInsetsBottomHeight

public static final @NonNull Modifier windowInsetsBottomHeight(
    @NonNull Modifier receiver,
    @NonNull WindowInsets insets
)

Sets the height to that of insets at the bottom of the screen.

When used, the android.view.WindowInsets will respect the consumed insets from windowInsetsPadding and consumeWindowInsets, but won't consume any insets.

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.windowInsetsTopHeight
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.core.view.WindowCompat

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            Box(Modifier.fillMaxSize()) {
                // Background for navigation bar at the bottom
                Box(Modifier.windowInsetsTopHeight(WindowInsets.navigationBars)
                    .fillMaxWidth()
                    .align(Alignment.BottomCenter)
                    .background(Color.Red)
                )
                // app content
            }
        }
    }
}

windowInsetsEndWidth

public static final @NonNull Modifier windowInsetsEndWidth(
    @NonNull Modifier receiver,
    @NonNull WindowInsets insets
)

Sets the width to that of insets at the end of the screen, using either left or right, depending on the LayoutDirection.

When used, the android.view.WindowInsets will respect the consumed insets from windowInsetsPadding and consumeWindowInsets, but won't consume any insets.

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.windowInsetsEndWidth
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.core.view.WindowCompat

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            Box(Modifier.fillMaxSize()) {
                // Background for navigation bar at the end
                Box(Modifier.windowInsetsEndWidth(WindowInsets.navigationBars)
                    .fillMaxHeight()
                    .align(Alignment.CenterEnd)
                    .background(Color.Red)
                )
                // app content
            }
        }
    }
}

windowInsetsStartWidth

public static final @NonNull Modifier windowInsetsStartWidth(
    @NonNull Modifier receiver,
    @NonNull WindowInsets insets
)

Sets the width to that of insets at the start of the screen, using either left or right, depending on the LayoutDirection.

When used, the android.view.WindowInsets will respect the consumed insets from windowInsetsPadding and consumeWindowInsets, but won't consume any insets.

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.windowInsetsStartWidth
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.core.view.WindowCompat

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            Box(Modifier.fillMaxSize()) {
                // Background for navigation bar at the start
                Box(Modifier.windowInsetsStartWidth(WindowInsets.navigationBars)
                    .fillMaxHeight()
                    .align(Alignment.CenterStart)
                    .background(Color.Red)
                )
                // app content
            }
        }
    }
}

windowInsetsTopHeight

public static final @NonNull Modifier windowInsetsTopHeight(
    @NonNull Modifier receiver,
    @NonNull WindowInsets insets
)

Sets the height to that of insets at the top of the screen.

When used, the android.view.WindowInsets will respect the consumed insets from windowInsetsPadding and consumeWindowInsets, but won't consume any insets.

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.windowInsetsTopHeight
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.core.view.WindowCompat

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            Box(Modifier.fillMaxSize()) {
                // Background for status bar at the top
                Box(Modifier.windowInsetsTopHeight(WindowInsets.statusBars)
                    .fillMaxWidth()
                    .align(Alignment.TopCenter)
                    .background(Color.Red)
                )
                // app content
            }
        }
    }
}