hi guys, do you know how can i detect when the `ba...
# compose
a
hi guys, do you know how can i detect when the
back
button has been pressed? i tried with all the
KeyboardActions
but none of them are triggered when i press that button 😕 (using BasicTextField)
r
a
i tried with this and didnt work
Copy code
.onKeyEvent {
                    if (it.nativeKeyEvent.keyCode == KEYCODE_DEL) {
                        onBack()
                    }
                    true
                }
r
Add a log to the top of that block and record the key code in the log. When you press the key you want, you’ll get the code back and you can register for that key press.
I recommend against setting that delete key as the back button, for whatever it’s worth
a
it doesn’t trigger the block, it does to alll other keys but no to
KEYCODE_DEL
😞
Copy code
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
            modifier = Modifier
                .align(Alignment.Center)
                .onKeyEvent {
                    Log.e("key", "${it.nativeKeyEvent.keyCode}")
                    if (it.nativeKeyEvent.keyCode == KEYCODE_DEL) {
                        onBack()
                    }
                    true
                }
                .focusRequester(focusRequester)
r
Well, the other route is to use imeOptions to make the actual back button available on the keyboard: https://developer.android.com/reference/android/widget/TextView#attr_android:imeOptions
actionPrevious
might be the one you’re looking for