我正在尝试设置一个如果文本字段的列表,当用户将焦点设置在底部的一个文本字段上时,我希望用户能够看到出现的IME软键盘和根据我的清单文件android:windowSoftInputMode="adjustPan",中的配置集填充的文本字段,但是它第一次不能工作,只有当列出的一些文本字段已经成为焦点时,它才能工作。
我在onCreate方法中的代码。
// Turn off the decor fitting system windows, which allows us to handle insets,
// including IME animations
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
// Provide WindowInsets to our content. We don't want to consume them, so that
// they keep being pass down the view hierarchy (since we're using fragments).
ProvideWindowInsets(consumeWindowInsets = false) {
MyApplicationTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background, modifier = Modifier.systemBarsPadding()) {
Column(modifier = Modifier.fillMaxHeight()) {
val list: List<@Composable () -> Unit> = (1..10).map {
{
Text(text = "$it")
Divider()
TextField(value = "", onValueChange = {}, modifier = Modifier.navigationBarsWithImePadding(),)
}
}
LazyColumn(modifier = Modifier.fillMaxSize().weight(1F)) {
itemsIndexed(list) { index, inputText ->
inputText()
}
}
}
}
}
}
}
发布于 2021-11-05 15:27:50
如果您的问题正在发生,请检查Jetpack组合装置。
只添加此依赖关系:
implementation 'com.google.accompanist:accompanist-insets:{insetsVersion}'
并使用Modifier.imePadding()
或自定义解决方案:
@Composable
fun ImeAvoidingBox() {
val insets = LocalWindowInsets.current
val imeBottom = with(LocalDensity.current) { insets.ime.bottom.toDp() }
Box(Modifier.padding(bottom = imeBottom))
}
https://stackoverflow.com/questions/67341839
复制相似问题