Reputation: 117597
When I disable the EditText with setEnabled(false)
or via the xml file android:enabled="false"
, the background color will be gray:
and if I change the background with a white color android:background="@color/white"
, I will lose the border:
So my question is, how to disable the EditText (I don't want any dialog to be pooped up on long-clicking on it) and keep the border as it is?
Upvotes: 1
Views: 6810
Reputation: 3571
Try using a TextView
instead with android:background="#FFFFFF"
.
you could also try android:focusable="false"
.
Upvotes: 0
Reputation: 117597
I found a way to do it:
android:editable="false"
android:cursorVisible="false"
editText.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
return true;
}
});
Upvotes: 1
Reputation: 6376
Your best bet would be to create your own State List Drawable, and specify the disabled background to be the same as the enabled state. You would need to create your own 9-Patch image, or you could also pull the resource files from the Android Open Source.
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
Here's a sample that I use for my EditText backgrounds:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active tab -->
<item android:state_focused="true"
android:drawable="@drawable/edittext_bg_selected" />
<!-- Inactive tab -->
<item android:state_focused="false"
android:drawable="@drawable/edittext_bg_unselected" />
<item android:state_enabled="false"
android:drawable="@drawable/edittext_bg_unselected" />
<!-- Add all of your other states -->
</selector>
You would just need to mess with the different states to create what works for you.
Upvotes: 3