yam*_*ama 5 android android-alertdialog kotlin android-jetpack-compose
我在 jetpack compose 中隐藏了导航栏。
但是,当我显示对话框时,导航栏也会显示。
我想在显示对话框时隐藏导航栏。
详情请看GIF动画
如果您有好主意,请告诉我。
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SampleComposeTheme {
var showDialog by remember { mutableStateOf(false) }
OutlinedButton(
onClick = { showDialog = true }
) {
Text("Button")
}
if (showDialog) {
AlertDialog(
onDismissRequest = {},
text = {
Text("Alert")
},
confirmButton = {
Button(onClick = { showDialog = false }) {
Text("ConfirmButton")
}
}
)
}
}
}
window.insetsController?.apply {
hide(WindowInsets.Type.navigationBars())
systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
}
Run Code Online (Sandbox Code Playgroud)

您可以使用 Google 的 Accompanist 库,它提供了用于更新 Compose 中的系统 UI 栏的实用程序。伴奏者
implementation "com.google.accompanist:accompanist-systemuicontroller:<version>"
val systemUiController = rememberSystemUiController()
systemUiController.isStatusBarVisible = false // Status bar
systemUiController.isNavigationBarVisible = false // Navigation bar
systemUiController.isSystemBarsVisible = false // Status & Navigation bars
systemUiController.navigationBarDarkContentEnabled =false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2708 次 |
| 最近记录: |