Interface

SoftwareKeyboardController

Provides manual, programmatic control over the software keyboard.

SoftwareKeyboardControllerSample

@Sampled
@Composable
fun SoftwareKeyboardControllerSample() {
    val keyboardController = LocalSoftwareKeyboardController.current

    // used to ensure a TextField is focused when showing keyboard
    val focusRequester = remember { FocusRequester() }
    val state = rememberTextFieldState("Close keyboard on done ime action (blue ✔️)")
    Column(Modifier.padding(16.dp)) {
        BasicTextField(
            state,
            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
            onKeyboardAction = { keyboardController?.hide() },
            modifier = Modifier.focusRequester(focusRequester).fillMaxWidth(),
        )
        Spacer(Modifier.height(16.dp))
        Button(
            onClick = {
                focusRequester.requestFocus()
                keyboardController?.show()
            },
            modifier = Modifier.fillMaxWidth(),
        ) {
            Text("Show software keyboard.")
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: