Harshal Kalavadiya
Harshal Kalavadiya

Reputation: 2436

Issue in Edittext Background opacity in android

I have two edittext in which i set opacity for that below is my images.

enter image description here

Below is my Layout Code

main.xml

   <EditText
        android:id="@+id/editText1"
         android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:alpha="0.23"
        android:ems="10"
        android:hint="Email"
         android:background="@drawable/backwithborder"
        android:padding="10dp"
        android:singleLine="true"
        android:textColorHint="@android:color/black"
       >
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:alpha="0.23"
        android:ems="10"
        android:background="@drawable/backwithborder"
        android:hint="Password"
        android:inputType="textPassword"
        android:padding="10dp"
        android:singleLine="true"
        android:textColorHint="@android:color/black"
         />

backwithborder.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<solid android:color="@android:color/white" />

<stroke
    android:width="1dip"
    android:color="#ffffff" />

MainActivity.java

    mEditTextU.setOnTouchListener(new View.OnTouchListener()
    {
        public boolean onTouch(View arg0, MotionEvent arg1)
        {
              mEditTextU.setAlpha(100.0f);
            return false;
        }
    });
    mEditTextP.setOnTouchListener(new View.OnTouchListener()
    {
        public boolean onTouch(View arg0, MotionEvent arg1)
        {

              mEditTextP.setAlpha(100.0f);
            return false;
        }
    });

when i run above code and focus in email edittext it opacity set like below image

enter image description here

but i want like this

enter image description here

so any idea how can i solve it ?

Upvotes: 2

Views: 3765

Answers (2)

sharath
sharath

Reputation: 521

The code android:padding="10dp" actually applies to your edittext and focuses it like you have mentioned.

Upvotes: 1

Pratik Butani
Pratik Butani

Reputation: 62421

I think you have problem with android:padding="10dp" that you have defined in both EditText, Try to remove it.

Reduced Code Like:

<EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:alpha="0.23"
        android:ems="10"
        android:hint="Email"
        android:background="@drawable/backwithborder"
        android:singleLine="true"
        android:textColorHint="@android:color/black" />

<EditText
        android:id="@+id/editText2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:alpha="0.23"
        android:ems="10"
        android:background="@drawable/backwithborder"
        android:hint="Password"
        android:inputType="textPassword"
        android:singleLine="true"
        android:textColorHint="@android:color/black" />

Upvotes: 1

Related Questions