A EditText is an overlay over TextView that configures itself to be editable. It is the predefined subclass of TextView that includes rich editing capabilities.
Android Studio:EditText editable is deprecated How to use inputType.
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
).
use EditText.setFocusable(false)
to disable editingEditText.setFocusableInTouchMode(true)
to enable editing;
You can try the following method :
private void disableEditText(EditText editText) {
editText.setFocusable(false);
editText.setEnabled(false);
editText.setCursorVisible(false);
editText.setKeyListener(null);
editText.setBackgroundColor(Color.TRANSPARENT);
}
Enabled EditText :
Disabled EditText :
It works for me and hope it helps you.
Use this to disable user input
android:focusable="false"
android:editable="false" This method is deprecated one.
For disable edit EditText
, I think we can use focusable
OR enable
but
Using android:enabled=...
or editText.setEnabled(...)
It also changes the text color in EditText
to gray.
When clicked it have no effect
Using android:focusable=...
or editText.setFocusable(false)
- editText.setFocusableInTouchMode(true)
It doesn't change text color of EditText
When clicked it highlights the EditText
bottom line for about few millisecond
Output
As android:editable="false"
deprecated
In xml
Use
android:enabled="false"
it's simple. Why use more code?
If you want in java class
you can also use this programmatically
editText.setEnabled(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With