Avatar ·

How to programmatically hide keyboard in Jetpack Compose when working with TextField

Hello everyone! I started learning Jetpack Compose and encountered this problem: after the user enters text in the TextField, the keyboard does not close automatically. I need it to hide when the "Done" button is pressed or after form submission. In classic View, this was done via InputMethodManager, but in Compose it doesn't work directly.

\n\n

Here is my current code:

\n\n
@Composable\nfun LoginScreen() {\n    var text by remember { mutableStateOf("") }\n    \n    Column(\n        modifier = Modifier.fillMaxSize().padding(16.dp)\n    ) {\n        OutlinedTextField(\n            value = text,\n            onValueChange = { text = it },\n            label = { Text("Enter name") },\n            modifier = Modifier.fillMaxWidth()\n        )