简体   繁体   English

Jetpack Compose - 键盘第一次隐藏 TextField

[英]Jetpack Compose - Keyboard hides TextField first time

I have create a simple example with six TextFields inside a LazyColumn, when you click the last TextField, the keyboard hides it, if you hide the keyboard and click again last TextField, works fine.我在 LazyColumn 中创建了一个包含六个 TextField 的简单示例,当您单击最后一个 TextField 时,键盘会将其隐藏,如果您隐藏键盘并再次单击最后一个 TextField,则效果很好。

In the AndroidManifest I use "adjustPan"在 AndroidManifest 中我使用“adjustPan”

        android:windowSoftInputMode="adjustPan"

This is a capture when you click the last TextField first time, hides the last TextField这是第一次单击最后一个 TextField 时的捕获,隐藏了最后一个 TextField

This is a capture when you click the last TextField second time, works correctly这是您第二次单击最后一个 TextField 时的捕获,可以正常工作

This is the code这是代码

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            TestComposeTheme {
                val numbers = listOf(1,2,3,4,5,6)
                LazyColumn() {
                    items(numbers) { index->
                        TextField(index = index)
                    }
                }
            }
        }
    }
}
@Composable
fun TextField(index: Int){
    var text by remember { mutableStateOf("Hello$index") }
    TextField(
        modifier = Modifier.padding(25.dp),
        value = text,
        onValueChange = { text = it },
        label = { Text("TextField$index") }
    )
}

Does anyone know if there is any way that the first time the last TextField is tapped, it would prevent the keyboard from hiding it有谁知道第一次点击最后一个 TextField 时是否有任何方法可以防止键盘隐藏它

EDIT: There is a known issue: 192043120编辑:有一个已知问题: 192043120

This is already a known issue.这已经是一个已知问题。 https://issuetracker.google.com/issues/192043120 https://issuetracker.google.com/issues/192043120

One hack to overcome this is use a column with verticalScroll克服这个问题的一个技巧是使用带有 verticalScroll 的列

    Column(Modifier.verticalScroll(rememberScrollState(), reverseScrolling = true){
   // Content
}

put this in your app AndroidManifest.xml inside activity tag把这个放在你的应用程序 AndroidManifest.xml 里面的活动标签

<activity
    ...
    android:windowSoftInputMode="adjustResize|stateVisible">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM