Listen to every key event on the Android soft keyboard

I don't want to listen to a soft keyboard event. I've tried setOnKeyListener and setKeyListener and both don't work. Does anyone know how to listen to the soft keyboard?

+3


source to share


2 answers


Assuming you are using a soft keyboard on a newer version of Android, the following comment from the KeyEvent link explains the main limitations when receiving soft key events.

"Multiple and inventive ways of entering text can be used as soft input methods, there is no guarantee that any keystroke on the soft keyboard will result in a key event : this is at the discretion of the IME, and in fact sending such events is not recommended. You should never rely on receiving KeyEvents for any key via soft input. In particular, the default soft keyboard will never send any key event to any application targeting Jelly Bean or later, and will only dispatch events for some delete and return key presses in applications targeting Ice Cream Sandwich or earlier. Remember that other software input methods can never send key events regardless of version. such as IME_ACTION_DONE if you need some kind of soft keyboard interaction, as this gives the user more visibility into how your application will respond to keystrokes. "



I think using the TextWatcher interface will probably be as close as you get to get what you want.

+7


source


I had the same problem. But what I did was used by a library that is already executed. Check this link: androidLibrary

Just follow the step and you're done. Import the library and then use the code provided to you.

You will just need to import the dependencies, for example:

dependencies {
    compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.0.0'
}

      



And let's implement this method:

KeyboardVisibilityEvent.setEventListener(
        getActivity(),
        new KeyboardVisibilityEventListener() {
            @Override
            public void onVisibilityChanged(boolean isOpen) {
                // some code depending on keyboard visiblity status
            }
        });

      

This is the main function.

+3


source







All Articles