Keyboard clicking not response
liweijian opened this issue · 9 comments
@liweijian Hi. I am facing the same issue. And found a working solution. Just add a param for AndroidKeyboardView
like this.
class AndroidKeyboardView(context: Context, var callback:(cs: CharSequence) -> Unit )
val view = AndroidKeyboardView(this) { txt ->
currentInputConnection.commitText(txt, txt.length)
return@AndroidKeyboardView
}
And pass it layer by layer until KeyboardKey
. Finally, call it inside Box's clickable. May it help.
@liweijian Hi. I am facing the same issue. And found a working solution. Just add a param for
AndroidKeyboardView
like this.class AndroidKeyboardView(context: Context, var callback:(cs: CharSequence) -> Unit )
val view = AndroidKeyboardView(this) { txt -> currentInputConnection.commitText(txt, txt.length) return@AndroidKeyboardView }And pass it layer by layer until
KeyboardKey
. Finally, call it inside Box's clickable. May it help.
😕 Sorry guys. There is a easy way the do it.Just using LocalContext.curent
inside KeyboardKey
method. You can get the context that is an instance of ImeService.
@liweijian Hi. I am facing the same issue. And found a working solution. Just add a param for
AndroidKeyboardView
like this.class AndroidKeyboardView(context: Context, var callback:(cs: CharSequence) -> Unit )
val view = AndroidKeyboardView(this) { txt -> currentInputConnection.commitText(txt, txt.length) return@AndroidKeyboardView }And pass it layer by layer until
KeyboardKey
. Finally, call it inside Box's clickable. May it help.😕 Sorry guys. There is a easy way the do it.Just using
LocalContext.curent
insideKeyboardKey
method. You can get the context that is an instance of ImeService.
Can you show me how to do it?
If I use your method by passing callback, android studio gives warning regarding ViewConstructor and the char result is flaky
@frengky-sinaga Sorry for late reply. LocalContext.curent
is an instance of InputMethodService
. You can get the currentInputConnection
directly. No need callback.
@frengky-sinaga Sorry for late reply.
LocalContext.curent
is an instance ofInputMethodService
. You can get thecurrentInputConnection
directly. No need callback.
Can you show the sample code? Still cannot input the key from the keyboard
@frengky-sinaga Sorry for late reply.
LocalContext.curent
is an instance ofInputMethodService
. You can get thecurrentInputConnection
directly. No need callback.Can you show the sample code? Still cannot input the key from the keyboard
Check the fun KeyboardKey and the lines with comment.
@Composable
fun KeyboardKey(
keyboardKey: String,
modifier: Modifier,
) {
val context = LocalContext.current // An instance of IMEService
val interactionSource = remember { MutableInteractionSource() }
val pressed = interactionSource.collectIsPressedAsState()
Box(modifier = modifier) {
Text(keyboardKey, Modifier
.fillMaxWidth()
.padding(2.dp)
.border(1.dp, Color.Black)
.clickable(interactionSource = interactionSource, indication = null) {
(context as IMEService).currentInputConnection.commitText(keyboardKey, keyboardKey.length) // call commitText
}
.background(Color.White)
.padding(
start = 12.dp,
end = 12.dp,
top = 16.dp,
bottom = 16.dp
)
)
// ...
}
}
And if you can't get the context, check this link # How to get Context in Jetpack Compose.Good luck.
Can we directly implement IMEService to specific application without using these
-
ctx.startActivity(Intent(Settings.ACTION_INPUT_METHOD_SETTINGS))
-
inputMethodManager.showInputMethodPicker()