Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default disabled EditText's style?

It isn't looking nice when using EditText enabled="false". How can I change it automatically for all of the controls?

I've added this image for reference. enter image description here

Can someone help me? Thanks.

like image 623
Jose Antonio Benitez Montero Avatar asked May 02 '13 11:05

Jose Antonio Benitez Montero


People also ask

How do I turn off edit text on Android?

What should I set to disable EditText? It's possible to preserve both the style of the view and the scrolling behaviour. To disable an EditText while keeping this properties, just use UI. setReadOnly(myEditText, true) from this library.


1 Answers

Create a custom selector in drawables and set it as

<EditText android:textColor="@drawable/edit_text_selector" />

1) in 'colors.xml' define the color for enabled and disabled state:

<color name="enabled_color">#F7FE2E</color> <color name="disabled_color">#000000</color> 

2) in 'drawable/edit_text_selector.xml':

<selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_enabled="false" android:color="@color/disabled_color"/>     <item android:color="@color/enabled_color"/> </selector> 

3) in your layout.xml:

<EditText     android:id="@+id/customEditText"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:enabled="false"     android:text="Hello!"     android:textColor="@drawable/edit_text_selector" /> 
like image 67
Nico Avatar answered Oct 02 '22 09:10

Nico