如何在 Jetpack compose 中隐藏 TextField/BasicTextField 的 TextFieldCursorHandle?

Abh*_*bhi 4 android android-jetpack-compose android-compose-textfield

到目前为止我的解决方案是使用Transparent光标的颜色。
我正在寻找更好的方法来隐藏它(如果有的话)。

cursorBrush = SolidColor(Transparent)
Run Code Online (Sandbox Code Playgroud)

TextField 应该获得焦点,键盘应该打开并且用户应该能够键入输入。

截屏

问题是TextFieldCursorHandle输入文本后我仍然可以看到。

在此输入图像描述

Gab*_*tti 10

  • 在 中,BasicTextField您可以使用 隐藏光标cursorBrush = SolidColor(Unspecified)
  • 在中TextField你可以使用该属性colors = TextFieldDefaults.textFieldColors(cursorColor = Color.Unspecified)

TextFieldCursorHandle选定的文本使用由LocalTextSelectionColors.current 您提供的颜色您覆盖定义自定义的颜色TextSelectionColors

val customTextSelectionColors = TextSelectionColors(
    handleColor = Color.Transparent,
    backgroundColor = Color.Transparent
)

CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {
   BasicTextField(
       value = text,
       onValueChange = {text = it},
       cursorBrush = SolidColor(Unspecified)
   )

   TextField(
       value = text,
       onValueChange = {text = it},
       colors = TextFieldDefaults.textFieldColors(cursorColor = Color.Unspecified)
   )

}
Run Code Online (Sandbox Code Playgroud)