0

I want to make my EditText Opacity to 1 which will ensure that it looks like disabled. But since my API level is set to 8, i am not able to apply this method.

Is there anyway we can disable the EditText and Grey it out, so that i looks disabled.

theJava
  • 14,620
  • 45
  • 131
  • 172

2 Answers2

2

Try:

editText.setEnabled(false);

Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • I have already done it, but it does not look disabled for me. – theJava Jun 04 '13 at 13:16
  • Are you customising the background? Make sure your background drawable supports the disabled state. More info here: (http://stackoverflow.com/questions/5790454/disable-button-with-custom-background-android) it's about buttons but applies to EditText – Ken Wolf Jun 04 '13 at 13:18
  • – theJava Jun 04 '13 at 13:21
  • I am using the above style for my edit text, is it making some different. – theJava Jun 04 '13 at 13:21
  • Try changing the style to inherit from EditText - `parent="@android:style/Widget.EditText"` and see if that helps – Ken Wolf Jun 04 '13 at 13:23
2

Yes, you can use setEnabled(false) and then apply this kind of style on the button (in the layout xml file):

<item android:state_enabled="false" >
<shape>
            <gradient
                android:endColor="#007900"
                android:startColor="#009A77"
                android:angle="270" />
            <stroke
                android:width="1dp"
                android:color="#F1FAFE" />
            <corners
                android:radius="5dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
    </shape>
</item>

Customise the values with colors and effects you want.

Edit: You will find everything you want to learn how to apply a style on any UI element here: http://www.devahead.com/blog/2011/08/creating-a-custom-android-button-with-a-resizable-skin/ The example is about buttons but it is the exact same method for any other view.

YannPl
  • 1,312
  • 1
  • 14
  • 30