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?
If set, specifies that this
TextView
has an input method. It will be a textual one unless it has otherwise been specified. ForTextView
, this is false by default. ForEditText
, it is true by default.Must be a
boolean
value, eithertrue
orfalse
.This may also be a reference to a resource (in the form
@[package:]type:name
) or theme attribute (in the form?[package:][type:]name
) containing a value of this type.This corresponds to the global attribute resource symbol editable.
Related Methods
this is my implementation (a little long, but useful to me!): With this code you can make EditView Read-only or Normal. even in read-only state, the text can be copied by user. you can change the backgroud to make it look different from a normal EditText.
the benefit of this code is that, the EditText is displayed as normal EditText but the content is not changeable. The return value should be kept as a variable to one be able revert back from read-only state to normal.
to make an EditText read-only, just put it as:
and to make it normal use tw from previous statement:
This will give you uneditable EditText filter. you first need to put the text you want on the editText field and then apply this filter.
If you
setEnabled(false)
then youreditText
would look disabled (gray, etc). You may not want to change the visual aspect of your editor.A less intrusive way would be to use
setFocusable(false)
.I believe that this answers your question closer to your initial intent.
android:editable="false" has been depreciated. Therefore you cant use it to make the edit text readonly.
I have done this using the bellow solution. Here I have used
android:inputType="none"
android:textIsSelectable="true"
android:focusable="false"
Give it try :)
set in XML