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?
This code works great nice
use this class for root view:
}
and set keyboard listener in activity or fragment:
A different approach would be to check when the user stopped typing...
When a TextEdit is in focus (user is/was typing) you could hide the views (focus listener)
and use a Handler + Runnable and a text change listener to close the keyboard (regardless of its visibility) and show the views after some delay.
The main thing to look out for would be the delay you use, which would depend on the content of these TextEdits.
This is not working as desired...
... have seen many use size calculations to check ...
I wanted to determine if it was open or not and I found
isAcceptingText()
so this really does not answer the question as it does not address opening or closing rather more like is open or closed so it is related code that may help others in various scenarios...
in an activity
in a fragment
Jaap's answer won't work for AppCompatActivity. Instead get the height of the Status Bar and Navigation bar etc and compare to your app's window size.
Like so:
Piece of cake with the awesome KeyboardVisibilityEvent library: https://android-arsenal.com/details/1/2519
Support min SDK version is 14 for 2.0.0