Skip to content Skip to sidebar Skip to footer

Edittext Non Editable

I'm trying to make an EditText non editable with this code:

Solution 1:

android:editable="false" should work, but it is deprecated, you should be using android:inputType="none" instead.

Alternatively, if you want to do it in the code you could do this :

EditTextmEdit= (EditText) findViewById(R.id.yourid);
mEdit.setEnabled(false);

This is also a viable alternative :

EditTextmEdit= (EditText) findViewById(R.id.yourid);
mEdit.setKeyListener(null);

If you're going to make your EditText non-editable, may I suggest using the TextView widget instead of the EditText, since using a EditText seems kind of pointless in that case.

EDIT: Altered some information since I've found that android:editable is deprecated, and you should use android:inputType="none", but there is a bug about it on android code; So please check this.

Solution 2:

I guess I am late but use following together to make it work:

 android:inputType="none"
 android:enabled="false"

Solution 3:

In case you want to make an EditText not editable from code:

voiddisableInput(EditText editText){
    editText.setInputType(InputType.TYPE_NULL);
    editText.setTextIsSelectable(false);
    editText.setOnKeyListener(newView.OnKeyListener() {
        @OverridepublicbooleanonKey(View v,int keyCode,KeyEvent event) {
                returntrue;  // Blocks input from hardware keyboards.
        }
    });
}

In case you want to remove the horizontal line of your EditText, just add:

editText.setBackground(null);

If you want to let users copy the content of the EditText then use:

editText.setTextIsSelectable(true);

Solution 4:

 <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editTexteventdate"
            android:background="@null"
            android:hint="Date of Event"
            android:textSize="18dp"
            android:textColor="#fff"
            android:editable="false"
            android:focusable="false"
            android:clickable="false"

            />

Add this

android:editable="false"

android:focusable="false"

android:clickable="false"

its work for me

Solution 5:

If you really want to use an editText and not a textView, then consider using these three:

android:focusable="false"android:clickable="false"android:longClickable="false"

EDIT: The "longClickable" attribute disables the long press actions that cause the "Paste" and or "Select All" options to show up as a tooltip.

Post a Comment for "Edittext Non Editable"