SoFunction
Updated on 2025-04-07

Android's soft keyboard automatically pops up and closes [Code Sharing]

1: The soft keyboard automatically pops up.

private EditText top_middle;//Input box
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------top_middle.setFocusable(true);
top_middle.setFocusableInTouchMode(true);
top_middle.requestFocus();
InputMethodManager inputManager =
(InputMethodManager) top_middle.getContext().getSystemService(
   Context.INPUT_METHOD_SERVICE);
(top_middle, 0);
Timer timer = new Timer();
(new TimerTask()
{
  public void run()
  {
   InputMethodManager inputManager =
   (InputMethodManager) top_middle.getContext().getSystemService(
      Context.INPUT_METHOD_SERVICE);
   (top_middle, 0);
  }
},

998);

2: The soft keyboard will automatically close.

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------InputMethodManager imm = (InputMethodManager) (Context.INPUT_METHOD_SERVICE);
(top_middle.getWindowToken(), 0);

Three: The soft keyboard pops up and closes automatically in the dialog box.

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------getWindow().setSoftInputMode(.SOFT_INPUT_STATE_VISIBLE | .SOFT_INPUT_ADJUST_RESIZE);

The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!