Can anyone tell me how to make an EditText
not editable via XML? I tried setting android:editable
to false
, but
- it is deprecated; and
- it didn't work.
Can anyone tell me how to make an EditText
not editable via XML? I tried setting android:editable
to false
, but
I have faced same problem but after observation I found that
android:editable="false"
is only working when inputtype (android:inputType="ANY_VALUE"
) is not given in the Edittext.Remove inputType from EditText and use editable = false, its working fine.
If you want to do it in java code just use this line to disable it:
And this to enable it:
As mentioned in other answers, you can do a
setEnabled(false)
but since you are asking how to set it via XML, here is how to do it.Add the following attribute to your
EditText
:They made "editable" deprecated but didn't provide a working corresponding one in inputType.
By the way, does inputType="none" has any effect? Using it or not does not make any difference as far as I see.
For example, the default editText is said to be single line. But you have to select an inputType for it to be single line. And if you select "none", it is still multiline.
Just use
android:enabled="false"
. This will also give an appearance to theEditText
which will make it look not editable.disable from XML (one line):
re-enable from Java, if need be (also one line):