Hope you can help - I'm getting back to b4a, and been struggling with b4x pages, and keyboard when closing and opening.
On registration page, I need to push the view top by X, so it's show the input boxes behind the keyboard, I did saw there is an option to use scroll view, but I thought I try the IME from what I saw the tutorial, and other posts.
Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int)
Private IsIMEKeyboardClosed As Boolean = (NewHeight = ActivityHeight)
LogColor("IsIMEKeyboardClosed >> " & IsIMEKeyboardClosed, Colors.Red)
End Sub
My if check -
B4X:
If IsIMEKeyboardClosed = True Then
contentPanel.SetLayoutAnimated(400, contentPanel.Left, OriginalTop, contentPanel.Width, contentPanel.Height)
Else
contentPanel.SetLayoutAnimated(400, contentPanel.Left, OriginalTop - 120dip, contentPanel.Width, contentPanel.Height)
End If
Which does what it suppose to - I can move the layout to the top and see the input boxes, and keyboard closes and it's back to bottom.
However if I press the lock screen button on phone, and come back - this stop functioning and won't move the layout back to top by X
So, is this the best practice? and What is the solution to make the the IME_HeightChange triggers again after resume?
Sub Globals
Private ime As IME
End Sub
Sub Activity_Create(FirstTime As Boolean)
ime.Initialize("IME")
ime.AddHeightChangedEvent
Dim pm As B4XPagesManager
pm.Initialize(Activity)
End Sub...
Sub Globals
Private ime As IME
End Sub
Sub Activity_Create(FirstTime As Boolean)
ime.Initialize("IME")
ime.AddHeightChangedEvent
Dim pm As B4XPagesManager
pm.Initialize(Activity)
End Sub
Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
B4XPages.GetManager.RaiseEvent(B4XPages.GetManager.GetTopPage, "IME_HeightChanged", Array(NewHeight, OldHeight))
End Sub
Then, in each page where you need dynamic views based on keyboard height, you add your procedure. Here is an example of where I use it in Page_Login (A B4XPage for B4i/B4a):
B4X:
Private Sub B4XPage_KeyboardStateChanged(Height As Int)
#if b4i
If Height > 0 Then 'Keyboard Enter
loginPanel.Top = Root.Height - Height - loginPanel.Height - 20dip
Else
loginPanel.Top = (Root.Height / 2) - (loginPanel.Height /2)
End If
#Else If b4a
loginPanel.Top = (Height / 2) - (loginPanel.Height /2)
#End If
End Sub
This is great -- because you only need to define once in your main activity and can have your keyboard event throughout all of your pages.