I have an EditText widget in my view. When the user selects the EditText widget, I display some instructions and the soft keyboard appears.
I use an OnEditorActionListener to detect when the user has completed text entry and I dismiss the keyboard, hide the instructions and perform some action.
My problem is when the user dismisses the keyboard by pressing the BACK key. The OS dismisses the keyboard, but my instructions (which I need to hide) are still visible.
I've tried overriding OnKeyDown, but that doesn't seem to get called when the BACK button is used to dismiss the keyboard.
I've tried setting an OnKeyListener on the EditText widget, but that doesn't seem to get called either.
How can I detect when the soft keyboard is being dismissed?
Just create a class that extends Edittext and use that edittext in your code, you should just override the following method in the custom edittext:
Here's a solution with the key listener. I have no idea why this works but OnKeyListener works if you just purely override onKeyPreIme on your custom EditText.
SomeClass.java
CustomEditText.java
Jay, your solution is good ! thanks :)
I made a slight change on Jay's solution by calling super.onKeyPreIme():
Wonderful solution, Jay, +1!
Here is my custom EditText to detect whether keyboard is showing or not
For anyone looking to do the same in Xamarin, I've translated some of the top answers as it's a bit different. I created a gist here but summarizing, you create a custom EditText and override
OnKeyPreIme
like so:... and then in the view...