There are two methods: showSystemKeyboard and hideSystemKeyboard . I think everything is still logical, one method shows the keyboard, the other hides it.

The showSystemKeyboard keyboard show method in the onStart () method:

  @Override public void onStart() { super.onStart(); if (allAvailableTags.isEmpty() && selectedTags.isEmpty()) { Utils.showSystemKeyboard(tagNameInputView); } } 

The showSystemKeyboard method showSystemKeyboard :

 public static void showSystemKeyboard(EditText view) { if (view != null) { InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); } } 

The task is to call the dialog in my class TagDialog, where the onStart () method is implemented, the keyboard opens immediately. Immediately say the constant SHOW_FORCED does not fit right away. Who cares why, follow here .

Tried as follows:

  tagNameInputView.requestFocus(); tagNameInputView.postDelayed(new Runnable() { @Override public void run() { if (allAvailableTags.isEmpty() && selectedTags.isEmpty()) { InputMethodManager keyboard = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); keyboard.showSoftInput(tagNameInputView, 0); } } },200); tagNameInputView.requestFocus(); tagNameInputView.postDelayed(new Runnable() { @Override public void run() { InputMethodManager keyboard = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); keyboard.hideSoftInputFromWindow(tagNameInputView.getWindowToken(), 0); } },200); 

But you still have to click on the field before my keyboard opens.

  • Try using postDelayed requestFocus on the input field to do - YuriySPb
  • @YuriSPb unfortunately did not work. You still have to click on EditText before the keyboard opens. - Morozov
  • I had in mind including and the focus request is deferred to be done, also inside the run - YuriySPb
  • one
    Try this: stackoverflow.com/a/17238023/3212712 - Yuriy SPb
  • one
    This is the delay before calling run in milliseconds - YuriySPb

2 answers 2

 mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { InputMethodManager imm = (InputMethodManager) mActivityContext.get().getSystemService(Context.INPUT_METHOD_SERVICE); if (hasFocus) { imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.RESULT_SHOWN); } else { if (imm.isActive(v)) imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.RESULT_HIDDEN); } } }); 

After that, you need to call requestFocus () in the right place on the EditText and the keyboard will open.

    Thank you, handy answer Yuriyaspb.

    I implemented it in the onCreateView method as follows:

      if (allTags.isEmpty()) { getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); }