In my application, I have an EditText that the user only has 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 and I can change the text.
What should I set to disable EditText?
Today I still use
editable="false"
, but also withfocusable="false"
.I think the case we need to make an EditText un-editable, is because we want to keep its EditText style (with that underline, with hint, etc), but it accepts other inputs instead of text. For example a dropdown list.
In such use case, we need to have the
EditText
clickable (thusenabled="false"
is not suitable). Settingfocusable="false"
do this trick, however, I can still long hold on the EditText and paste my own text onto it from clipboard. Depending on your code and handling this can even crash your app.So I also used
editable="false"
and now everything is great, except the warning.you can use
android:focusable="false"
but also need to disable cursor otherwise copy/paste function would still work.so, use
You can try the following method :
Enabled EditText :
Disabled EditText :
It works for me and hope it helps you.
Set this in your XML code, It works.
android:focusableInTouchMode="false"
is now deprecated and use
if you use
android:editable="false"
, eclipse will remind you this message "android:editable is deprecated: Use inputType instead".So, I use
android:focusable="false"
instead, it worked well for me.