Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make EditText ReadOnly

People also ask

How do you make EditText read only?

The most reliable way to do this is using UI. setReadOnly(myEditText, true) from this library. There are a few properties that have to be set, which you can check out in the source code.

How do you make EditText not editable?

Make EditText non editable in Android To use this just set android:inputType="none" and it will become non editable.

What is EditText control?

Advertisements. 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.


Please use this code..

Edittext.setEnabled(false);

If you setEnabled(false) then your editText 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.


In XML use:

android:editable="false"

As an example:

<EditText
    android:id="@+id/EditText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:editable="false" />

This works for me:

EditText.setKeyListener(null);

editText.setInputType(InputType.TYPE_NULL);

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 to TYPE_NULL seems to be functionally equivalent to the depreciated android:editable="false". Additionally, android:inputType="none" seems to have no noticeable effect.