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

Mar 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 = trueeditText.isFocusableInTouchMode = trueeditText.inputType = TYPE_NULL

To enable focus and edit of EditText.

editText.isFocusable = trueeditText.isFocusableInTouchMode = trueeditText.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.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.