Android Question Determine keyboard status while in FullScreen in 2024

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone... I know that with IME is not possible to fire the HeightChanged event in fullscreen mode... is it possible that in 2024 there is no other option to have an event for the keyboard opening/hiding?... i think it is impossible that there is no other method... already in 2016 this user posted this question with an interesting point... "How can the BetterDialogs move the dialog above the keyboard? is not possible to exploit the same mechanism?"

However, in this Stackoverflow there is the Java version for something that can might work (2020 Update)

and also this (sperically for fullscreen acrivities)

I'm not able to convert this to B4A btw.
 
Last edited:
Solution
Hi, I've found the answer by myself

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("Layout")   


    ' --- Your code here ---


    ' =========================================================
    ' BYPASS FULLSCREEN
    ' =========================================================
    Dim jo As JavaObject = Me   
    Dim NativeRootView As JavaObject = Root
    jo.RunMethod("ListenToKeyboard", Array(NativeRootView))
End Sub

Private Sub keyboard_heightchanged (NewHeight As Int, OldHeight As Int)
    ' Your logic here for the Layout.
End Sub

#If Java
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import anywheresoftware.b4a.BA;

public void...

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi, I've found the answer by myself

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("Layout")   


    ' --- Your code here ---


    ' =========================================================
    ' BYPASS FULLSCREEN
    ' =========================================================
    Dim jo As JavaObject = Me   
    Dim NativeRootView As JavaObject = Root
    jo.RunMethod("ListenToKeyboard", Array(NativeRootView))
End Sub

Private Sub keyboard_heightchanged (NewHeight As Int, OldHeight As Int)
    ' Your logic here for the Layout.
End Sub

#If Java
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import anywheresoftware.b4a.BA;

public void ListenToKeyboard(final View rootView) {
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        int previousHeight = -1;

        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();

            // Get the visible screen window
            rootView.getWindowVisibleDisplayFrame(r);

            // r.bottom is the lowest visible poit
            // If the keyboard opens this values decreases
            int visibleHeight = r.bottom;

            if (previousHeight != visibleHeight) {
                if (previousHeight != -1) {
                    // Trigger B4A event
                    ba.raiseEventFromUI(null, "keyboard_heightchanged", visibleHeight, previousHeight);
                }
                previousHeight = visibleHeight;
            }
        }
    });
}
#End If
 
Upvote 0
Solution

b4x-de

Active Member
Licensed User
Longtime User
I know that with IME is not possible to fire the HeightChanged event in fullscreen mode...
Be aware that this constraint is not true anymore. The solution is provided here:

 
Upvote 0
Top