0

How can I prevent the dragging functionality of BasicTextField. I dont want the user to be able to drag the text and make it invisible. Below a video with the functionality that I want to disable.

enter image description here

This my code:

@Composable
fun MyScreen() {
  var input by remember {
    mutableStateOf("")
  }
  Column(Modifier.padding(16.dp).fillMaxWidth()) {
    BasicTextField(
      modifier = Modifier.align(CenterHorizontally).width(IntrinsicSize.Min),
      value = input,
      singleLine = true,
      onValueChange = { input = it },
      textStyle = MaterialTheme.typography.h3,
      decorationBox = { innerTextField ->
        if (input.isEmpty()) {
          Text(
            text = "0",
            style = MaterialTheme.typography.h3,
            color = MaterialTheme.colors.onBackground.copy(alpha = 0.3f)
          )
        }
        innerTextField()
      }
    )
  }
}
Diego Palomar
  • 6,958
  • 2
  • 31
  • 42

1 Answers1

0

It should be fixed by replacing singleLine=true with minLines=1; maxLines=1.

Please note this behavior is not the same as regular TextView, where you usually want android:singleLine for the proper IME action support.

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428