textfield失去了懒惰的焦点

发布于 2025-02-10 19:48:06 字数 1024 浏览 1 评论 0原文

我正在尝试构建一个UI,该UI在懒惰的布局中包含一个搜索栏。唯一的问题是,如果Textfield不在屏幕顶部,则它将失去焦点。

代码:

        val listState = rememberLazyListState()
        LazyColumn(
            modifier = Modifier.padding(horizontal = 16.dp),
            state = listState,
        ) {
            items(7) { // it works with 5 items, but with 7 it doesn't
                QuickStart()
            }

            var text by remember { mutableStateOf(value = "") }
            TextField(
                value = TextFieldValue(text = text),
                onValueChange = { text = it.text }
            )
        }

我共享了GIF可视化问题。

说明: TextField视图获得焦点,然后失去它,因此系统关闭了键盘。

“不工作示例”

说明:当TextField上方没有很多元素时,视图如预期的那样工作。在上面添加7个元素之后,它停止工作。

“工作示例”

是否有任何解决方案,以便我可以在列表中的其他地方添加EditText?

I'm trying to build an UI that contains a search bar inside a LazyColumn layout. The only problem is that the TextField loses focus if it is not at the top of the screen.

Code:

        val listState = rememberLazyListState()
        LazyColumn(
            modifier = Modifier.padding(horizontal = 16.dp),
            state = listState,
        ) {
            items(7) { // it works with 5 items, but with 7 it doesn't
                QuickStart()
            }

            var text by remember { mutableStateOf(value = "") }
            TextField(
                value = TextFieldValue(text = text),
                onValueChange = { text = it.text }
            )
        }

I've shared gifs visualizing the issue.

Explanation: The TextField view gets focus and then loses it, therefore the system closes the keyboard.

Not Working Example

Explanation: The view works as expected when there are not many elements above the TextField. It stops working after adding 7 elements above it.

Working Example

Is there any solution, so that i can add the edittext somewhere further in the list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文