Ilhem Nemri Ilhem Nemri - 5 months ago 30
Android Question

Change EditText alpha without affecting the drawable and text opacity

I want this result :

enter image description here

but im having this:

enter image description here

I'am using this code :

<EditText
android:id="@+id/autoCompleteTextView1"
android:inputType="textAutoComplete|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:ems="10"
android:gravity="center"
android:hint="Destination *"
android:textColor="#ffffff"
android:textColorHint="#FFFFFF"
android:textSize="20sp"
android:background="#4d98d1"
android:alpha="0.2"
android:drawableLeft="@drawable/d"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:paddingLeft="30sp"
android:paddingRight="26dip"
android:focusable="false"/>


is there any change that I can apply here? or if I can do it programatically?

Answer

Defining the background as an ARGB color (with transparent alpha value) might work.

For example, change:

android:background="#4d98d1" 

to:

android:background="#804d98d1"

Check out this answer on alpha hex values for more information.