If I create a simple app with single Activity that contains a single EditText, and I do
EditText editText = (EditText) findViewById(R.id.editText);
editText.setTextIsSelectable(true);
then this prevents the keyboard from appearing (in my tests on Android 5.0 and 7.1). This is what I want, as requested in these questions:
- Disable soft-keyboard from EditText but still allow copy/paste?
- How to disable Android Soft Keyboard for a particular activity?
- Android: Disable soft keyboard at all EditTexts
- How to disable keypad popup when on edittext?
- Disable keyboard on EditText
The source code is
public void setTextIsSelectable(boolean selectable) {
if (!selectable && mEditor == null) return; // false is default value with no edit data
createEditorIfNeeded();
if (mEditor.mTextIsSelectable == selectable) return;
mEditor.mTextIsSelectable = selectable;
setFocusableInTouchMode(selectable);
setFocusable(selectable);
setClickable(selectable);
setLongClickable(selectable);
// mInputType should already be EditorInfo.TYPE_NULL and mInput should be null
setMovementMethod(selectable ? ArrowKeyMovementMethod.getInstance() : null);
setText(mText, selectable ? BufferType.SPANNABLE : BufferType.NORMAL);
// Called by setText above, but safer in case of future code changes
mEditor.prepareCursorControllers();
}
But I don't see what about this disables the Input Method from appearing.
Calling the following methods all return true
whether I set setTextIsSelectable
or not.
editText.isFocusable(); // true
editText.isFocusableInTouchMode(); // true
editText.isClickable(); // true
editText.isLongClickable(); // true
I'm partly asking because I'm curious, but also because I need to disable the system keyboard in my app. I want to understand what is happening so that I can be sure that it is really doing what I think it is doing.
Update
Follow-up question and answer: