android-softkeyboard - Jetpack 撰写 LazyColumn 或 Scrollable Column 和 TextField 的 IME 填充不起作用
问题描述
我正在尝试设置一个文本字段列表,当用户将焦点设置在底部的一个文本字段上时,我希望用户可以看到出现的 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()
}
}
}
}
}
}
}
解决方案
如果您的问题仍然存在,请检查Jetpack Compose 的插图。
仅添加此依赖项:
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))
}
推荐阅读
- python - 使用 python 网络爬虫抓取 Twitter 帐户
- sharepoint - SharePoint 站点和图形 API(测试版)- 在站点下找不到任何页面并且无法创建页面(访问被拒绝)
- firebase - 如何将 firebase-database 作为 es6 模块导入
- python - 将包含对象的 dict 转换为 DataFrame
- c# - 在段落元素内动态生成 span 元素
- java - 将域名动态传递到 Spring Jpa 中的 a href 链接
- python - 基于 Q-learning 的最短路径算法
- jquery - 单击数字键盘JS或Jquery时用数字修改类名的一部分?
- visual-studio-code - 在VS Code中双击一个数字时,是否可以让它忽略单位?(忽略“12px”中的“px”)
- python - 使用相同的变量再次运行while循环并再次启动脚本而不关闭它?