0

How to listen for a system button to hide the keyboard in order to remove focus from the input field? Like, for example, in Google Keep.

@Composable
fun PrerequisiteAddScreen() {
    var value by remember { mutableStateOf("") }
    val focusManager = LocalFocusManager.current

    SelectionContainer {
        TextField(
            value = value,
            onValueChange = { value = it },
            placeholder = { Text("Enter text") },
            keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Default, keyboardType = KeyboardType.Text)
        )
    }

    if (...) {
        focusManager.clearFocus()
    }
}
pie
  • 127
  • 9
  • 1
    does [this](https://stackoverflow.com/a/68420874/3585796) answer your question? – Phil Dukhov May 16 '22 at 17:02
  • 1
    @PylypDukhov Yes. That's what I need. Thank you! But keep in mind that this does not work when starting the preview view. You need to start the activity itself. – pie May 16 '22 at 18:06

0 Answers0