Jetpack Compose:ModalBottomSheet在部分设备被软键盘遮挡问题求助
Jetpack Compose ModalBottomSheet 软键盘遮挡兼容问题
我在使用Jetpack Compose和ModalBottomSheet时遇到兼容问题:部分设备的软键盘会遮挡ModalBottomSheet内容。搭载Android 14、OneUI 6.1的三星Galaxy S24 Ultra,以及搭载Android 15的谷歌Pixel 6a均正常显示,但搭载Android 12、OneUI 4.1的三星Galaxy A52s出现遮挡情况。经过数小时调试与尝试,我仍未找到问题根源。当前使用Compose Compiler版本2.0.10与Material3,相关代码如下:
AppHost 代码
Scaffold( modifier = Modifier.fillMaxSize() ) { padding -> Box( modifier = Modifier .fillMaxSize(), contentAlignment = Alignment.TopCenter ) { Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter ) { DestinationsNavHost( navGraph = NavGraphs.root, engine = engine, navController = navController, defaultTransitions = DefaultEatDeTransitions, modifier = Modifier .fillMaxSize() .consumeWindowInsets(padding) .imePadding() ) ... } } }
DefaultBottomSheet 代码
@OptIn(ExperimentalMaterial3Api::class) @Composable fun DefaultBottomSheet( visible: Boolean, onDismissRequest: () -> Unit, sheetState: SheetState = rememberModalBottomSheetState(), scrimColor: Color = Color.Black.copy(alpha = .6F), content: @Composable ColumnScope.() -> Unit ) { if (visible) { ModalBottomSheet( onDismissRequest = onDismissRequest, sheetState = sheetState, properties = ModalBottomSheetDefaults.properties( shouldDismissOnBackPress = false ), dragHandle = { Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally ) { StatusBarSpacer(color = Color.Transparent) DefaultDragHandle() } }, containerColor = MaterialTheme.colorScheme.background, scrimColor = scrimColor, shape = RoundedCornerShape( topStart = 16.dp, topEnd = 16.dp ), windowInsets = WindowInsets( bottom = 0 ), content = { content.invoke(this) NavigationBarSpacer() } ) } }
内容的提问来源于stack exchange,提问作者Daniel
相关产品推荐
相关产品推荐

