Android Question How to detect if IME soft keyboard is closed?

agraham

Expert
Licensed User
Longtime User
Android IME was handling has always been rubbish, though I think Android 11 or 12 improved things a bit with an imnproved API but that doesn't really help until (if ever) most devices out there are updated. See if GetKeyboardRectangle in my IME2 library does what you want.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Hello everyone, I tried to use the IME_HeightChanged(NewHeight As Int, OldHeight As Int) event to hide my AdMob banner when the user is typing but I am unable to use this to know if the keyboard was closed back.
You can compare NewHeight to the activity / root height.
 
Upvote 0

FrostCodes

Active Member
Licensed User
Longtime User
My Final Code:

B4X:
Sub Globals
    Private ActivityHeight As Int = 0
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    ActivityHeight = Activity.Height
End Sub

B4X:
Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int)
    Private IsIMEKeyboardClosed As Boolean = (NewHeight = ActivityHeight)
    LogColor("IsIMEKeyboardClosed >>   " & IsIMEKeyboardClosed, Colors.Red)
End Sub
 
Upvote 0
Top