项目场景:

Jetpack Compose 实现沉浸式状态栏


实现效果:

在这里插入图片描述

在这里插入图片描述

实现步骤:

第一步:
添加依赖

	implementation "com.google.accompanist:accompanist-insets:0.15.0"
    implementation "com.google.accompanist:accompanist-insets-ui:0.15.0"
    implementation "com.google.accompanist:accompanist-systemuicontroller:0.15.0"

若为gradle.kts中添加依赖则改为:

    implementation("com.google.accompanist:accompanist-insets:0.15.0")
    implementation( "com.google.accompanist:accompanist-insets-ui:0.15.0")
    implementation("com.google.accompanist:accompanist-systemuicontroller:0.15.0")

compose
compose - Docker Compose是一个用于定义和运行多容器Docker应用程序的工具,通过Compose文件格式简化应用部署过程。

第二步:
在Activity的onCreate中添加:

window.setDecorFitsSystemWindows(false)

此时已经实现了不再为状态栏与导航栏预留位置(即与页面重叠),但状态栏与导航栏会遮挡。


第二步:
将导航栏设为透明

rememberSystemUiController().setStatusBarColor(Color.Transparent, darkIcons = MaterialTheme.colors.isLight)

若使用Material3则使用:

rememberSystemUiController().setStatusBarColor(Color.Transparent, darkIcons = true)

添加位置如下:
在这里插入图片描述


推荐内容
GitHub 加速计划 / compose / compose
86
5
下载
compose - Docker Compose是一个用于定义和运行多容器Docker应用程序的工具,通过Compose文件格式简化应用部署过程。
最近提交(Master分支:7 个月前 )
51907d9f Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> 2 天前
a3f88a0a Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com> 2 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐