Android Question How to keep the virtual keyboard closed

EduardoElias

Well-Known Member
Licensed User
Longtime User
I use Android Box to run an app for data entry and it is connected using a real keyboard.

However when typing in a edit text android show up the virtual keyboard at same time.

I have to install a null keyboard an use it as the default, because most of these androids does not have an option to turn off the virtual keyboard

I would like to know if there is a way using b4a to disable the virtual keyboard while using an text editor control
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I use Android Box to run an app for data entry and it is connected using a real keyboard.

However when typing in a edit text android show up the virtual keyboard at same time.

I have to install a null keyboard an use it as the default, because most of these androids does not have an option to turn off the virtual keyboard

I would like to know if there is a way using b4a to disable the virtual keyboard while using an text editor control
You can also disable the keyboard with Java. I do this as I only run my own custom keyboard and sofar this has always worked fine.
In a B4XPages project you will need this code:

In Main:

B4X:
#IF JAVA
    import android.widget.EditText;
    import android.os.Build;
    import android.text.InputType;

 public void disableSoftKeyboard(final EditText v) {
    if (Build.VERSION.SDK_INT >= 11) {
        v.setRawInputType(InputType.TYPE_CLASS_TEXT);
        v.setTextIsSelectable(true);
        v.setShowSoftInputOnFocus(false);
     } else {
        v.setRawInputType(InputType.TYPE_NULL);
        v.setFocusable(true);
     }
}

 public static void enableSoftKeyboard(final EditText v, int iKeyBoardType) {
    if (Build.VERSION.SDK_INT >= 11) {
        v.setRawInputType(iKeyBoardType);
        v.setTextIsSelectable(true);
        v.setShowSoftInputOnFocus(true);
     } else {
        v.setRawInputType(iKeyBoardType);
        v.setFocusable(true);
     }
                     
}
#END IF

In B4XMainPage (or where ever else):

B4X:
Sub Class_Globals
     Public NativeMe As JavaObject
End Sub

Sub DisableKeyboard(edt as EditText)
    If NativeMe.IsInitialized = False Then
        NativeMe.InitializeContext
    End If
    NativeMe.RunMethod("disableSoftKeyboard", Array As Object(edt))
End Sub

DisableKeyboard will need to run for every EditText.

RBS
 
Upvote 0
Top