Compose Modifier

windowInsetsTopHeight

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

insetsTopHeightSample

@Sampled
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
                }
            }
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: