Alex
Alex

Reputation: 1593

Prevent soft input from appearing

I have a Bluetooth barcode scanner attached to Android tablet. Hardware keyboard is disabled in Android setting. This allows me both scanning barcodes and using soft keyboard for typing.

When I scan a barcode, my activity catches all keys as expected. But the soft keyboard appears.

How to prevent the soft keyboard from appearing?

I have tried the followings:

android:windowSoftInputMode=stateHidden

or

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

(or stateAlwaysHidden),

but nothing worked. When the app catches hardware keydown, the soft keyboard appears.

Upvotes: 2

Views: 314

Answers (3)

kike
kike

Reputation: 4463

This one works for me:

public static void hideSoftInput(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view == null) view = new View(activity);
    InputMethodManager imm = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

Upvotes: 0

ismail alaoui
ismail alaoui

Reputation: 6073

please add this attribute to your activity in the manifest :

  android:windowSoftInputMode="stateHidden"

Upvotes: 0

Alok Gupta
Alok Gupta

Reputation: 1360

In the manifest, would you please try the following

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
          android:label="@string/app_name"
          android:windowSoftInputMode="stateHidden">

Upvotes: 1

Related Questions