I have an EditText where I want to process the input myself, so I don’t want the soft keyboard to appear when I click on it (or when the selection changes, focus changes, long press, etc.). However, I still want to be able to select the text, reposition the cursor, copy / past, etc.
I tried putting android: windowSoftInputMode = "stateAlwaysHidden" in the manifest, but that does not seem to do much. I also tried adding the following
edittext.setOnTouchListener(new OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
EditText edittext = (EditText) v;
int inType = edittext.getInputType();
edittext.setInputType(InputType.TYPE_NULL);
edittext.onTouchEvent(event);
edittext.setInputType(inType);
return true;
}
});
which disables the keyboard and also obstructs the cursor.
Currently, I'm basically trying to add listeners for all situations where a keyboard may appear to switch it, but it is very awkward, and I cannot catch all the cases. Is there a better way to disable the soft keyboard for a specific EditText or fragment?
source
share