I created a custom EditText by extending android.widget.EditText .
I would like auto-correct intervals to be visible only when EditText has focus. Therefore, I call setInputType(INPUT_NO_FOCUS); in the constructor and:
@Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(focused, direction, previouslyFocusedRect); if (focused) { setInputType(INPUT_FOCUS); } else { setInputType(INPUT_NO_FOCUS); } }
with:
private final int INPUT_NO_FOCUS = TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; private final int INPUT_FOCUS = TYPE_CLASS_TEXT | TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLET;
==> Actually there is no automatic correction and automatic completion, but it does not appear after clicking on EditText . Input type successfully changed.
How to enable automatic correction / add autofill?
// Change:
User Case I want to archive:
MyEditText extends EditText displayed and not focused. There is no spell check in the text (-> There are no red spaces / lines below the text)
The user clicks in the edit box. β Spell check starts β Red lines appear (user can click misspelled words and let the OS fix them)
The user clicks on another View element β Red lines / spaces disappear.
source share