Jetpack Compose 如何在离开构图时反转边到边

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

我想实现无边框屏幕(仅适用于应用程序中的特定屏幕),并且我正在使用 ComponentActivity

enableEdgeToEdge()
方法。我想在退出此屏幕时恢复之前的设置。好像没有相反的方法可以调用。

    
    @Composable
    fun FullScreen() {
        val context = LocalContext.current as ComponentActivity
    
        DisposableEffect(Unit) {
            context.enableEdgeToEdge()
            onDispose {
                // context.disableEdgeToEdge() <-- HOW TO ACHIEVE THIS?
            }
        }
    
        Column(
            modifier = Modifier
                .padding(vertical = 200.dp)
                .fillMaxSize(),
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.spacedBy(20.dp),
        ) {
            Text(text = "This is full screen!", style = MaterialTheme.typography.headlineMedium)
        }
    }

当我按下后退按钮时,前一个屏幕现在也是边缘到边缘的,这是我不想要的。

android-activity android-jetpack-compose android-statusbar android-compose
1个回答
0
投票

写了一些拐杖来绕过它

val componentActivityContext = LocalContext.current as ComponentActivity
val navBarArgbColor by remember { mutableIntStateOf(getNavBarArgbColor(view)) }
DisposableEffect(Unit) {
    componentActivityContext.enableEdgeToEdge()
    onDispose {
        dropNavBarAfterEdgeToEdge(view, navBarArgbColor)
    }
}

private fun getNavBarArgbColor(view: View): Int {
    val window = (view.context as Activity).window
    return window.navigationBarColor
}

private fun dropNavBarAfterEdgeToEdge(view: View, previousArgbColor: Int) {
    val window = (view.context as Activity).window
    window.navigationBarColor = previousArgbColor
}
© www.soinside.com 2019 - 2024. All rights reserved.