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?
It's 2019 now...
So I created a more neat solution with Kotlin
1.Create an extension function:
2.Where the toggle listener is:
3.Use it in any Activity as simple as this:
Using @olivier_sdg's answer, but converted to Kotlin:
hideSoftInputFromWindow
returns true when keyboard closes use it's value to detect keyboard close in androidI know a way to do this. Subclass the EditText and implement:
Here is a link on how to use your custom views (for when you subclass EditText): http://developer.android.com/guide/topics/ui/custom-components.html