Can anyone tell me how to make an EditText
not editable via XML? I tried setting android:editable
to false
, but
Add this to your EditText xml file:
<EditText ...
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false">
</EditText>
It will do the same effect as android:editable="false"
. Worked for me, hope it'll work for you too.
I tried to do:
textView.setInputType( InputType.TYPE_NULL );
which should work, but for me it did not.
I finished with this code:
textView.setKeyListener(new NumberKeyListener() {
public int getInputType() {
return InputType.TYPE_NULL;
}
protected char[] getAcceptedChars() {
return new char[] {};
}
});
which works perfectly.
As you mentioned android:editable is deprecated. android:inputType="none" should be used instead but it does not work due to a bug (https://code.google.com/p/android/issues/detail?id=2854)
But you can achieve the same thing by using focusable.
Via XML:
<EditText ...
android:focusable="false"
</EditText>
From code:
((EditText) findViewById(R.id.LoginNameEditText)).setFocusable(false);
android:editable is deprecated so use inputType instead.
<EditText
android:id="@+id/editText_x"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="70"
android:inputType="none"
android:hint="@string/enter_x" />
android:focusable="false"
android:clickable="false"
android:longClickable="false"
The "longClickable" attribute disables the long press actions that cause the "Paste" and or "Select All" options to show up as a tooltip.
Try this code. It's working in my project, so it will work in your project.
android:editable="false"