This question already has an answer here:
I am trying to listen for events that occurs when the keyboard is shown or hidden. Is this possible in Android? I am not trying to figure out if the keyboard is shown or hidden when I start my activity, I would like to listen for events.
Try below code:-
or
or
for below code you have to extend LinearLayout.
see below link:-
How to capture the "virtual keyboard show/hide" event in Android?