I have an Activity
where there are 5 EditText
s. When the user clicks on the first EditText
, the soft keyboard opens to enter some value in it. I want to set some other View
's visibility to Gone
when the soft keyboard opens and also when the user clicks on the first EditText
and also when the soft keyboard closes from the same EditText
on the back button press. Then I want to set some other View
's visibility to visible.
Is there any listener or callback or any hack for when the soft keyboard opens from a click on the first EditText
in Android?
You can use my Rx extension function (Kotlin).
Example:
For the case of
adjustResize
and FragmentActivity accepted solution from @Jaap doesn't work for me.Here is my solution:
Different implementation of a soft-keyboard-listener that DOES NOT RELY ON WINDOW-RESIZING & therefore also works nicely in the multi-window world. it has its own quirks of course, but imo they are nothing compared to the complete brokenness that is multi-window&window-resize-detection together.
Would appreciate ideas for improvements!
For Activity:
For Fragment:
This only works when
android:windowSoftInputMode
of your activity is set toadjustResize
in the manifest. You can use a layout listener to see if the root layout of your activity is resized by the keyboard.I use something like the following base class for my activities:
The following example activity uses this to hide a view when the keyboard is shown and show it again when the keyboard is hidden.
The xml layout:
And the activity:
when keyboard show
is true,else hide