Show Android Soft Keyboard Programmatically

--

In my last project I need to show Android soft keyboard automatically on a particular EditText when user navigate to a screen. The working code for my app is this two lines of code:

// 1
editText.requestFocus()

// 2
(getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
  1. We request a focus on the EditText so if the keyboard visible and user enter some data, this EditText value will change accordingly.
  2. We request system service to force soft input to be shown. There are other code tha could do the same, but this one is tested working on Xiaomi, so I use this one.

--

--

No responses yet