B4A Library ABKeyboardVisible

This is a small library I've used in one of our projects where the activity is full screen and I needed to know if the soft keyboard was open or closed.

The lib code is very simple, so I'm even wondering if this couldn't been done using inline Java in B4A (maybe someone has an idea how?)

This is the source code of the lib for those interested in the Java part:

package com.ab.abkeyboardvisible;

import android.graphics.Rect;
import android.view.View;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

public class ABKeyboardVisible {
   public boolean IsVisible(View decorView, boolean doLog) {
     Rect rect = new Rect();
     int displayHight = rect.bottom - rect.top;
     int height = decorView.getHeight();
     boolean hide = (double)displayHight / height > 0.8 ;
     if (doLog) {
       BA.Log("DecorView display hight = "+displayHight);
       BA.Log("DecorView hight = "+ height);
       BA.Log("softkeyboard visible = " + !hide);
     return !hide;

' first we need the DecorView of the activity
Dim jo As JavaObject = activity
Dim DecorView As View = jo.RunMethod("getRootView", Null)
If DecorView <> Null Then
     ' check if the keyboard is visible
     Dim keybVis As ABKeyboardVisible
     Dim KeyboardVisible As Boolean = keybVis.IsVisible(DecorView, False)
     If KeyboardVisible Then
     end if
end if

Attached is the library.


  • ABKeyboardVisible.zip
    2.2 KB · Views: 186