如何通过在jetpack compose中滑动来显示完全透明的系统栏?

问题描述 投票:0回答:1

我需要完全透明的系统栏通过滑动来显示然后隐藏。现在应用程序启动时它会隐藏

但是滑动后它不会隐藏。

我尝试过使用

systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE 

但这并没有帮助。请帮忙!

代码

setContent {
            Puzzle_QuestTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    val systemUiController = rememberSystemUiController()
                    systemUiController.setStatusBarColor(color = Transparent)
                    systemUiController.setNavigationBarColor(color =Transparent,darkIcons = false)
                    systemUiController.isNavigationBarContrastEnforced = false
                    systemUiController.isNavigationBarVisible = false
                    systemUiController.isSystemBarsVisible = false
                    systemUiController.isStatusBarVisible = false
                    PuzzleQuestApp()
                }
            }
        }
android android-jetpack-compose uinavigationbar swipe statusbar
1个回答
0
投票

设置systemBarsBehavior后

setContent {
    Puzzle_QuestTheme {
        Surface(
            modifier = Modifier.fillMaxSize(),
            color = MaterialTheme.colorScheme.background
        ) {
            val systemUiController = rememberSystemUiController()
            val window = LocalContext.current.window

            LaunchedEffect(Unit) {
                val controller = WindowInsetsControllerCompat(window, window.decorView)
                controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
                controller.hide(WindowInsetsCompat.Type.systemBars())
            }

            systemUiController.setStatusBarColor(color = Color.Transparent)
            systemUiController.setNavigationBarColor(color = Color.Transparent, darkIcons = false)
            systemUiController.isNavigationBarContrastEnforced = false

            PuzzleQuestApp()
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.