Can anyone tell me how to make an EditText
not editable via XML? I tried setting android:editable
to false
, but
Try this :
android:inputType="none"
Try
.setInputType(InputType.TYPE_NULL);
Short answer:
I used android:focusable="false"
and it worked. Click listening is also working now.
When I want an activity to not focus on the EditText and also not show keyboard when clicked, this is what worked for me.
Adding attributes to the main layout
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
and then the EditText field
android:focusable="false"
android:focusableInTouchMode="false"
Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_home"
android:background="@drawable/bg_landing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="@dimen/activity_vertical_margin"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
tools:context="com.woppi.woppi.samplelapp.HomeActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/fromEditText"
android:layout_weight="1"
android:hint="@string/placeholder_choose_language"
android:textColor="@android:color/white"
android:textColorHint="@android:color/darker_gray"
android:focusable="false"
android:focusableInTouchMode="false"
android:onClick="onSelectFromLanguage" />
</RelativeLayout>
This way did the job for me, i can selec and copy to clipboard, but i can't modify or paste.
android:enable="true"
android:textIsSelectable="true"
android:inputType="none"
I have faced same problem but after observation I found that android:editable="false"
is only working when inputtype (android:inputType="ANY_VALUE"
) is not given in the Edittext.
Remove inputType from EditText and use editable = false, its working fine.