B4A Library ABKeyboardVisible

Discussion in 'Additional libraries, classes and official updates' started by alwaysbusy, Mar 31, 2015.

  1. alwaysbusy

    alwaysbusy Expert Licensed User

    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) {
    "DecorView display hight = "+displayHight);
    "DecorView hight = "+ height);
    "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.

    Attached Files:

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice