When a Dialog is popped up, if the Dialog needs to input data, and then the input method needs to be closed after confirmation, there will always be various problems in the hide and show methods of the system, the most aggressive solution is to write a timer to pop up or close the input method on a regular basis.
Import java. util. timer; import java. util. timerTask; import android. content. context; import android. view. view; import android. view. inputmethod. inputMethodManager; import android. widget. editText; public class InputTools {// hide the virtual keyboard public static void HideKeyboard (View v) {InputMethodManager imm = (InputMethodManager) v. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); if (imm. isActive () {imm. hideSoftInputFromWindow (v. getApplicationWindowToken (), 0) ;}// display the virtual keyboard public static void ShowKeyboard (View v) {InputMethodManager imm = (InputMethodManager) v. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); imm. showSoftInput (v, InputMethodManager. SHOW_FORCED);} // force display or disable the public static void KeyBoard (final EditText txtSearchKey, final String status) {Timer timer = new Timer (); timer. schedule (new TimerTask () {@ Override public void run () {InputMethodManager m = (InputMethodManager) txtSearchKey. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); if (status. equals ("open") {m. showSoftInput (txtSearchKey, InputMethodManager. SHOW_FORCED);} else {m. hideSoftInputFromWindow (txtSearchKey. getWindowToken (), 0) ;}}, 300) ;}// use a timer to forcibly hide the virtual keyboard public static void TimerHideKeyboard (final View v) {Timer timer = new Timer (); timer. schedule (new TimerTask () {@ Override public void run () {InputMethodManager imm = (InputMethodManager) v. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); if (imm. isActive () {imm. hideSoftInputFromWindow (v. getApplicationWindowToken (), 0) ;}}, 10) ;}// whether the input method displays public static boolean KeyBoard (EditText edittext) {boolean bool = false; inputMethodManager imm = (InputMethodManager) edittext. getContext (). getSystemService (Context. INPUT_METHOD_SERVICE); if (imm. isActive () {bool = true;} return bool ;}}