键盘与 ModalBottomSheet 上的 TextField 重叠(Jetpack compose)

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

设备的键盘与具有文本字段的 ModalBottomSheet 重叠,我已经在清单文件中设置了

android:windowSoftInputMode="adjustResize"
并在底部工作表内容中消耗了
imePadding

这是我到目前为止的代码:

主要活动
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    @OptIn(ExperimentalMaterial3Api::class)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val loadProfileModalBottomSheetState = rememberModalBottomSheetState()
            val saveProfileModalBottomSheetState = rememberModalBottomSheetState()
            val scope = rememberCoroutineScope()
            val navController = rememberNavController()
            EqualizerTheme {
                Scaffold(
                    modifier = Modifier.fillMaxSize(),
                    topBar = {...}
                ) { paddingValues ->
                    MainNavGraph(navController = navController, paddingValues = paddingValues)
                    if (loadProfileModalBottomSheetState.isVisible) {
                        LoadProfilesBottomSheet(
                            sheetState = loadProfileModalBottomSheetState,
                            onHide = { scope.launch { loadProfileModalBottomSheetState.hide() } }
                        )
                    }
                    if (saveProfileModalBottomSheetState.isVisible){
                        SaveProfileBottomSheet(
                            sheetState = saveProfileModalBottomSheetState,
                            onHide = { scope.launch { saveProfileModalBottomSheetState.hide() } }
                        )
                    }
                }
            }
        }
    }
}
底部表
@Composable
fun SaveProfileBottomSheet(
    modifier: Modifier = Modifier,
    sheetState: SheetState,
    onHide: () -> Unit,
    viewModel: ProfileStorageViewModel = hiltViewModel()
) {
    val state = viewModel.state.collectAsState().value

    ModalBottomSheet(
        modifier = modifier,
        sheetState = sheetState,
        onDismissRequest = {
            onHide()
        }
    ) {
        SaveProfileBottomSheetContent(
            modifier = Modifier.imePadding(),
            profileName = state.profileName,
            onProfileNameChange = viewModel::onProfileNameChange,
            onHide = {
                onHide()
            },
            onSave = {
                onHide()
                viewModel.onSave()
            }
        )
    }
}

enter image description here

android-jetpack-compose android-jetpack bottom-sheet uikeyboard
1个回答
0
投票

我解决了这个问题 设置模态底部表单的 fillMaxSize。 然后我使用此方法将模态底部工作表的状态设置为文本字段的ExpandedonValueChange

suspend fun expandBottomSheet() {
if (bottomSheetState.hasPartiallyExpandedState) {
       bottomSheetState.expand()
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.