Skip to content

Instantly share code, notes, and snippets.

@RaheemJnr
Created October 22, 2021 09:31
Show Gist options
  • Save RaheemJnr/f194c0e0076a0b018e6ff21b8521ed63 to your computer and use it in GitHub Desktop.
Save RaheemJnr/f194c0e0076a0b018e6ff21b8521ed63 to your computer and use it in GitHub Desktop.
@ExperimentalComposeUiApi
@Composable
fun ShowKeyboard() {
val keyboardController = LocalSoftwareKeyboardController.current
var value by remember { mutableStateOf("") }
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center
) {
TextField(
value = value,
onValueChange = { value = it },
modifier = Modifier
.padding(8.dp)
.fillMaxWidth(),
)
Spacer(modifier = Modifier.height(12.dp))
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceEvenly
) {
//show keyboard
Button(
onClick = {
keyboardController?.show()
}
) {
Text(text = "Show")
}
//hide keyboard
Button(
onClick = { keyboardController?.hide() }
) {
Text(text = "Hide")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment