I want to make a read-only EditText
view. The XML to do this code seems to be android:editable="false"
, but I want to do this in code.
How can I do this?
I want to make a read-only EditText
view. The XML to do this code seems to be android:editable="false"
, but I want to do this in code.
How can I do this?
writing this two line is more than enough for your work.
Try using
As per the docs this prevents the soft keyboard from being displayed. It also prevents pasting, allows scrolling and doesn't alter the visual aspect of the view. However, this also prevents selecting and copying of the text within the view.
From my tests setting
setInputType
toTYPE_NULL
seems to be functionally equivalent to the depreciatedandroid:editable="false"
. Additionally,android:inputType="none"
seems to have no noticeable effect.Set this in EdiTextView xml file
This works for me:
Use this code:
Disabling editText gives a read-only look and behavior but also changes the text color to gray so setting its text color is needed.