3

The solution I have so far is to use a Transparent Color for the cursor.
I am looking for a better way to hide it if there is any.

cursorBrush = SolidColor(Transparent)

TextField should be focused, the keyboard should be open and the user should be able to type input.

Screenshot

The problem with this is I can still see the TextFieldCursorHandle after entering text.

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Abhimanyu
  • 11,351
  • 7
  • 51
  • 121

1 Answers1

7
  • In the BasicTextField you can hide the cursor using cursorBrush = SolidColor(Unspecified).
  • In the TextFieldyou can use the attribute colors = TextFieldDefaults.textFieldColors(cursorColor = Color.Unspecified)

The TextFieldCursorHandle and the selected text use the color provided by LocalTextSelectionColors.current You override this color defining a custom 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)
   )

}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841