Android EditText Disable Edit and Focus (read only TextView behaviour) Without Disable

March 31, 2019

If you disable EditText using setEnabled(false), the style/color will change to light gray.

To disable EditText (no focus and edit) wihout disabling it.

editText.isFocusable = true
editText.isFocusableInTouchMode = true
editText.inputType = TYPE_NULL

To enable focus and edit of EditText.

editText.isFocusable = true
editText.isFocusableInTouchMode = true
editText.inputType = InputType.TYPE_CLASS_TEXT

Create an Kotlin extension

fun EditText.setReadOnly(value: Boolean, inputType: Int = InputType.TYPE_NULL) {
    isFocusable = !value
    isFocusableInTouchMode = !value
    this.inputType = inputType
}

Else, you could show a TextView which look like EditText.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.