junior dev
junior dev

Reputation: 11

How to detect android soft keyboard "Will Show" event

I have a cordova android app. I'm trying to prevent native android keyboard to show when user clicks on html input, or input gets focus programmatically. It there for android something like:

keyboard.addEventListener('will-show', 
   functon(event){
     event.disableKeyboardShow();
});

Thanks in advance!

Upvotes: 1

Views: 583

Answers (1)

I don't know if there is an event like you pointed. But you can prevent keyboard to showup automatically by doing this:

1) Insert on your onCreate():

    InputMethodManager imm = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
    View view = this.getCurrentFocus();
    if (view == null) {
        view = new View(this);
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

2) Then you assure your EditText can get focus when needed by adding android:focusable="true" and android:focusableInTouchMode="true" elements in the parent layout of EditText like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout" android:focusable="true" android:focusableInTouchMode="true">

If you don't want your EditText to get focus anyway, put false at elements on step 2 and insert another one: android:descendantFocusability="blocksDescendants"

Upvotes: 1

Related Questions