gpt4 book ai didi

android - 如何获取 TextField (Jetpack Compose) 的光标位置?

转载 作者:行者123 更新时间:2023-12-05 05:38:56 26 4
gpt4 key购买 nike

对于常规的EditText,我们可以通过调用getSelectionStart() 方法来获取光标位置。在 Jetpack Compose 中,这种可能性适用于 ClickableText,但显然不适用于 TextField 或 OutlinedTextField。

有没有人遇到过这个问题并知道如何解决?

最佳答案

For a regular EditText, we can get the cursor position by calling the getSelectionStart() method

那是因为 EditText 是有状态的。

In Jetpack Compose this posibility is available for ClickableText, but apparently not for TextField or OutlinedTextField.

可组合项是无状态的。

Has anyone come across this problem and know how to solve it?

In the case of BasicTextField()和相关的可组合物,use the composable where your state is TextFieldValue .然后,TextFieldValueselection 属性有一个 TextRange,您可以使用它来获取光标位置。

关于android - 如何获取 TextField (Jetpack Compose) 的光标位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72808695/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com