1、沉浸式界面:隐藏顶部状态栏
// 隐藏顶部状态栏
WindowCompat.setDecorFitsSystemWindows(window, false)
主题:
@Composable
fun Compose_FullScreen(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
(view.context as Activity).window.statusBarColor = Color.Transparent.toArgb() // 状态栏透明
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
}
}
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content
)
}
或者可以使用activity1.8.0的版本中的
enableEdgeToEdge()
2、距离顶部状态栏的高度
Modifier.systemBarsPadding()