Disabling of EditText in Android


Question

In my application, I have an EditText that user only have Read access not Write access.

In code I set android:enabled="false".

Although the background of EditText changed to dark, when I click on it the keyboard pops up up and I can change text.

What should I set to disable EdidText?

Thanks.

1
167
6/20/2019 7:23:33 AM

Accepted Answer

I believe the correct would be to set android:editable="false".

And if you wonder why my link point to the attributes of TextView, you the answer is because EditText inherits from TextView:

EditText is a thin veneer over TextView that configures itself to be editable.

Update:
As mentioned in the comments below, editable is deprecated (since API level 3). You should instead be using inputType (with the value none).

221
2/6/2013 9:17:36 AM

use EditText.setFocusable(false) to disable editing
EditText.setFocusableInTouchMode(true) to enable editing;


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon