I'm new to Android compose. Is there any way to dismiss dialog on click of Done key from keyboard using ImeAction?
Currently below code is clearfocus on click of Done along with how to dismiss the dialog:
TextField(
value = text,
onValueChange = {
text = it
},
singleLine = true,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(
onDone = { focusRequester.requestFocus() }
),
modifier = Modifier.onKeyEvent {
if (it.nativeKeyEvent.keyCode == KeyEvent.KEYCODE_ENTER){
focusRequester.requestFocus()
true
}
false
}
)
MutableState<Boolean>
. In that case just set that to false, or call the method you call to hide the dialog insideonDone
method. Refer to the answer below. – Apologetic