How can I disable typing in an EditText
field in Android?
-
1Disable Keyboard on input in EditText ? – Kartik Domadiya May 04 '11 at 06:13
-
1There are two editText fields.First is for entering email.if the email is valid then the second editText field is to be enabled.but the problem is while typing an invalid email and clicking on the next button on the soft keyboard it goes to the second text field and can enter data eventhough i've made edittext.setEnabled(false).i am using android 2.3.1 – aj10 May 04 '11 at 06:46
18 Answers
you can use EditText.setFocusable(false)
to disable editingEditText.setFocusableInTouchMode(true)
to enable editing;

- 13,589
- 4
- 59
- 72

- 1,726
- 2
- 17
- 13
-
6This was my issue. I assumed that after `setFocusable(false)` I could just flip setFocusable(true)... not the case. Setting `setFocusableInTouchMode(true)` did the trick for me. – timgcarlson Jul 17 '15 at 22:55
In code:
editText.setEnabled(false);
Kotlin:
editText.isEnabled = false
Or, in XML:
android:enabled="false"

- 85
- 1
- 9

- 13,860
- 4
- 38
- 45
I think its a bug in android..It can be fixed by adding this patch :)
Check these links
question 1
and
question 2
Hope it will be useful.
-
119For those who'd rather see the code right here rather than use a hyperlink: `editText.setEnabled(false);`, in combination with `editText.setFocusable(false);` will achieve this. – Mxyk Jan 09 '12 at 15:00
-
9The same works with XML: `android:enabled="false"` and `android:focusable="false"`. Thanks guys! – jelies Jan 21 '13 at 19:45
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.

- 533
- 9
- 14

- 1,693
- 16
- 18
-
good answer but it can be improved by removing the line in which the background color is being change and add editText.setKeyListener(null); – Syed Raza Mehdi Aug 30 '16 at 09:45
Just set focusable property of your edittext to "false" and you are done.
<EditText
android:id="@+id/EditTextInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="right"
android:cursorVisible="true">
</EditText>
Below options doesn't work
In code:
editText.setEnabled(false);
Or, in XML:
android:editable="false"

- 2,272
- 1
- 25
- 26
Edittext edittext = (EditText)findViewById(R.id.edit);
edittext.setEnabled(false);

- 14,011
- 2
- 83
- 54
Enable:
private void enableEditText() {
mEditText.setFocusableInTouchMode(true);
mEditText.setFocusable(true);
mEditText.setEnabled(true);
}
Disable:
private void disableEditText() {
mEditText.setEnabled(false);
mEditText.setFocusable(false);
mEditText.setFocusableInTouchMode(false);
}

- 4,149
- 2
- 33
- 40
You can write edittext.setInputType(0)
if you want to show the edittext but not input any values

- 76,472
- 17
- 159
- 346

- 5,975
- 3
- 32
- 30
The below code disables the EditText in android
editText.setEnabled(false);
-
just set focusable property of your edittext to "false" and you are done.
edittext.setFocusable(false);
edittext.setEnabled(false);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
//removes on screen keyboard

- 8,923
- 3
- 40
- 52

- 377
- 2
- 8
According to me...if you have already declared the edittext
in the XML file and set the property in the XML file "android:enabled=false"
and disable at runtime to it at that time in java file adding only 2 or 3 lines
- First create the object
- Declare EditText et1;
Get by id
et1 = (EditText) FindViewById(R.id.edittext1);
et1.setEnabled(false);
You can do enable or disable to every control at run time by java file and design time by XML file.

- 576
- 1
- 10
- 19

- 31
- 4
The XML editable
property is deprecated since API LEVEL 15.
You should use now the inputType
property with the value none
.
But there is a bug that makes this functionality useless.
Here you can follow the issue status.

- 574
- 6
- 20
Write this in parent:
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
Example:
<RelativeLayout
android:id="@+id/menu_2_zawezanie_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/menu_2_horizontalScrollView"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:background="@drawable/rame">
<EditText
android:id="@+id/menu2_et"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/menu2_ibtn"
android:gravity="center"
android:hint="@string/filtruj" >
</EditText>
<ImageButton
android:id="@+id/menu2_ibtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@null"
android:src="@drawable/selector_btn" />

- 13
- 5
Set inputType
attribute to none in your layout.xml file under EditText

- 3,343
- 3
- 42
- 81

- 13
- 3
Right click the text area and untick the editable option:

- 2,775
- 7
- 20
- 26
-
Welcome to Stack Overflow, Nuwan Bandara. Your answer is related to JTextArea and not EditText, which is from Android Framework. It is unlikely that you are providing an answer for this question. – Igor Escodro Dec 18 '19 at 17:06