We just launched Compose Examples featuring over 150+ components! Check it out →

windowInsetsTopHeight

Common

Modifier in Compose Foundation Layout

Sets the height to that of [insets] at the [top][WindowInsets.getTop] of the screen.

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

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation-layout:1.8.0-alpha04")
}

Overloads

@Stable
fun Modifier.windowInsetsTopHeight(insets: WindowInsets)

Code Example

insetsTopHeightSample

fun insetsTopHeightSample() {
    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
                }
            }
        }
    }
}
by @alexstyl