I am using a custom in-app keyboard, so I need to disable the system keyboard. I can do that with
editText.setShowSoftInputOnFocus(false);
for Android API 21+. But to do the same thing down to API 11, I am doing
editText.setTextIsSelectable(true);
Sometimes I want to show the system keyboard again after disabling it with setTextIsSelectable
. But I can't figure out how. Doing the following does show the system keyboard, but if the user hides the keyboard and then clicks the EditText again, the keyboard still won't show.
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, 0);
I guess I could do editText.setOnFocusChangeListener
and then manually show or hide the system keyboard, but I would prefer to undo whatever setTextIsSelectable
did. The following also does not work:
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.setLongClickable(true);
How do I do it?
Short answer
Doing the following will reverse the effects of
setTextIsSelectable(true)
and allow the keyboard to show again when theEditText
receives focus.Explanation
The thing that prevents the keyboard from showing is
isTextSelectable()
beingtrue
. You can see that here (thanks to @adneal).The source code for
setTextIsSelectable
isThus, the code in the short answer section above first sets
mTextIsSelectable
tofalse
withsetTextIsSelectable(false)
and then undoes all of the other side effects one-by-one.