How to show fully transparent system bars by swiping in jetpack compose?

182 Views Asked by At

I need my fully transparent system bars to show by swiping and then hide. Now it is hidden when the app starts
enter image description here.

But after swiping it doesn't hide.

enter image description here

If I use

val activity = LocalContext.current as Activity
with(WindowCompat.getInsetsController(activity.window, activity.window.decorView)) { systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE }
 

the system bar will have a gray tint.

enter image description here

I need absolutely transparent bar without any shades... Please help!

The code

WindowCompat.setDecorFitsSystemWindows(window, false)
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()
                }
            }
        }
1

There are 1 best solutions below

1
Hezy Ziv On

after setting 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()
        }
    }
}