-4

I have an application with an EditText element on the next view. This means that when my application is loaded the soft keyboard appears per default.

What code do I use to hide this keyboard on IntelliJ?

UPDATE

4 Answers4

0

For Hiding keyboard, you can have two ways:

Either: (This will hide the keyboard on app/activity launch)

put this android:windowSoftInputMode="adjustPan" in activity tag of related activity in manifest.xml as:

<activity
        android:name=".MainActivity"
        android:windowSoftInputMode="adjustPan" />

Or:

put this method in your activity and call it whenever you have to hide the keyboard.

    @SuppressWarnings("ConstantConditions")
    public void hideKeyBoard(View view) {
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }

and call it as hideKeyBoard(view);.

Remember, you have to pass the view to hide the keyboard as above.

Lalit Fauzdar
  • 3,813
  • 2
  • 12
  • 39
0

Easiest way

in your onCreate()

   this.getWindow().setSoftInputMode
    (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Sometimes this won't work. So what you can do is, make your editText -> focusable as false inside your XML.

Daksh Gargas
  • 2,567
  • 1
  • 15
  • 28
0

This is my method for showing and hiding keyboard, called from an activity or fragment

public void hideKeyboard(final boolean hide) {
    // Check if no view has focus:
    View view = this.getCurrentFocus();
    if (view == null) {
        return;
    }
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (hide) {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    } else {
        new Handler().postDelayed(() -> imm.showSoftInput(view, 0), 50);
    }
}
revilo
  • 121
  • 1
  • 7
0

In Manifest put android:windowSoftInputMode="adjustPan" under your activity on which you want to hide soft keyboard like:

    <activity android:name=".Viewschedule"
          android:screenOrientation="portrait"
          android:windowSoftInputMode="adjustPan"></activity>

OR

   InputMethodManager imgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  imgr.showSoftInput(view, 0);
NipunPerfect
  • 127
  • 1
  • 7