0

I'm trying to detect when the soft keyboard gets closed, I found this code snippet

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
   if (event.getKeyCode() == KeyEvent.KEYCODE_BACK){
          //detects that keyboard was hidden
       }
       return super.onKeyPreIme(keyCode, event);
   }

but this needs to be added to a subclass that extends editText, I'm not intrested in implementing the functionality I want to add on keyboard hidden in all my app, I want to add it for just one Activity, I tried onKeyDown, onKeyBack, onKeyUp, onBackPressed nothing seems to log the back press that closes the soft keyboard.

so my question is there a way to detect the click on the button that hides the keybaord?

helpME
  • 1
  • 2
  • There are several reasons why the keyboard might become hidden. It seems you want to detect the keyboard hiding, not the keypress as such? If so, [that might be tricky](https://stackoverflow.com/questions/3568919/android-how-can-i-tell-if-the-soft-keyboard-is-showing-or-not)... – Thomas Aug 25 '20 at 18:22
  • I did want to do that initially, but all the solutions online were suggesting to calculate the height difference of the screen and the screen with the keyboard but it seems like it is always running in the background. I'd like to avoid that, I much rather have a trigger to check.. I'm using the imeOptions to hide the keyboard, but I still need to detect the back click that hides the keyboard – helpME Aug 25 '20 at 18:32

0 Answers0