Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force to remove keyboard after shown with SHOW_FORCED

Tags:

android

I show keyboard with code

        ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                .toggleSoftInput(InputMethodManager.SHOW_FORCED,
                        InputMethodManager.HIDE_IMPLICIT_ONLY);
        etContent.requestFocus();

In next step I inflate new LinearLayout and call setContentView(newLayout) and keyboard is still there. How to force to remove keyboard ? I tried with

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

but it didn't help. Can somebody suggest me solution ?

like image 836
Damir Avatar asked Nov 14 '11 16:11

Damir


People also ask

How do I force close an Android keyboard?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow , passing in the token of the window containing your focused view. This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.

How do I get rid of soft keyboard on Android?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.

How do I hide the soft keyboard on Android after clicking outside EditText Kotlin?

This example demonstrates how to hide a soft keyboard on android after clicking outside EditText using Kotlin. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


2 Answers

Try this out. I've used this to hide the soft input a number of times.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getContentView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
like image 161
JoeLallouz Avatar answered Nov 13 '22 05:11

JoeLallouz


Try this, it should work

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getContentView().getWindowToken(), 0);
like image 40
koder Avatar answered Nov 13 '22 06:11

koder