How to forcefully remove a keyboard after showing with SHOW_FORCED

I am showing a keyboard with a code

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

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

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

but it did not help. Can someone suggest me a solution?

+4
source share
2 answers

Try it. I used this to hide soft input several 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); 
+7
source

Try it, it should work

 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getContentView().getWindowToken(), 0); 
0
source

Source: https://habr.com/ru/post/1381160/


All Articles