I used IME HeightChanged to detect the display of the keyboard and place the input field upper the keyboard as mentionned it in an old post. It works well except when the smartphone turned off the screen because of standby. In that case, event returns a NewHeight greater than Height of the screen. So you need to test NewHeight versus min(OldHeight,100%y) :
HeightChanged Event:
Sub KBOARD_HeightChanged(NewHeight As Int, OldHeight As Int)
Log("100%y="&100%y& " New="&NewHeight&" Old="&OldHeight)
Dim kbaff As Boolean
kbaff = (NewHeight<OldHeight)
Log("KO : Keyboard "&IIf(kbaff,"shown","hidden"))
kbaff = (NewHeight<Min(OldHeight,100%y))
Log("OK : Keyboard "&IIf(kbaff,"shown","hidden"))
End Sub
100%y) instead
Above the log in the IDE : I touch the input field to display the keyboard, then touch to hide it, then wait the standby and finally turns it on :
Logger connecté à : samsung SM-A405FN
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
100%y=1942 New=1017 Old=1942
KO : Keyboard shown
OK : Keyboard shown
100%y=1942 New=1942 Old=1017
KO : Keyboard hidden
OK : Keyboard hidden
** Activity (main) Pause, UserClosed = false **
Ignoring event: kboard_heightchanged
** Activity (main) Resume **
100%y=1942 New=1942 Old=2086
KO : Keyboard shown
OK : Keyboard hidden
I've added it. I don't see the behavior you are describing though there are all kinds of quirks in Android related to the handling of activity resizes. The values come from the OS.
IME handling in Android is a bit of a nightmare, it was badly designed from the start although recent API changes have made it a bit less bad. You could look at my IME2 library to see if there is anything there that helps your situation.
I have been having a lot of trouble lately with layouts being corrupted when rotating a device with the soft keyboard open. The problem stems from trying to use the IME library HeightChanged event. Unfortunately Android provides no direct way to determine whether the soft keyboard is shown or...
Thanks for your answers. I added the manifest option but it didn't change anything (and I think it is not surprising as I already received the event) : the height is still 2086 instead of 1942 on my Samsung A40. Perhaps the difference could be the title bar height when coming from standby on some OS/devices ?
I will try IME2 a bit later as I have an easy workaround but I will have a look !
As Promised, I did the test and the results seem to be the same (I am not sure of the interpretation as heights are not the same). But IME and IME2 seem to returns values in the same way.
The code with IME (the event) and IME2 (var KB2):
Sub KBOARD_HeightChanged(NewHeight As Int, OldHeight As Int)
Dim k As Rect = KB2.GetKeyboardRect, d As Rect = KB2.GetDisplayRect, w As Rect = KB2.GetWindowRect
Dim aff As Boolean = (NewHeight<Min(100%y,OldHeight))
Dim status As String = "Keyboard "&IIf(aff,"displayed","hidden")
Log(status&CRLF&"--> Old:"&OldHeight&" New:"&NewHeight)
Log("--> KB2 heights Keyb:"&k.Height&" Disp:"&d.Height&" Win:"&w.Height)
End Sub
And the log resulting of running the application, showing and hidding the keyboard, waiting for standby and finally resuming :
Logger connecté à : samsung SM-A405FN
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Hi,
I downloaded your demo app and added an EditText (EditText2) view to the lower part of the layout, making it to be covered by the keyboard when it is displayed.
I was expecting the EditText2 to "move up" above the keyboard (to become visible) when touching into this view, but it did not.
What would be the fix to this so that views that are placed lower on a layout to become visible when they get focus?