showSoftInput()
doesn\'t show the keyboard for me, but toggleSoftInput()
does. I saw some other post that said to disable the hard keyboard when us
Show Keyboard + focus and also if you want to Hide the keyboard
@Override
public void onResume () {
super.onResume();
inputSearch.setFocusableInTouchMode(true);
inputSearch.requestFocus();
// Show Keyboard
InputMethodManager imm = (InputMethodManager) getSherlockActivity().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(inputSearch, InputMethodManager.SHOW_IMPLICIT);
}
P.S inputSearch = (EditText) getSherlockActivity().findViewById(R.id.inputSearch);
// Hide Keyboard
InputMethodManager imm = (InputMethodManager) getSherlockActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(inputSearch.getWindowToken(), 0);
ShowSoftInput works if the imm's target view is same with the editText.
You can check this by imm.isActive(editText)
or editText.isInputMethodTarget()
.
ToggleSoftInput is just toggling the keyboard of the current target of imm.
Target view of imm is set after the focus has been changed by editText.requestFocus()
. I think some post processes exist between these two tasks since one post runnable was not enough. I tested double post and it worked for me.
editText.requestFocus();
editText.post(new Runnable() {
@Override
public void run() {
editText.post(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(editText, 0);
}
}
});
}
});