how add a border only on bottom of EditText?

simple create one edittext_bottom_line.xml file in drawable folder in res

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

    <item android:bottom="1dp"
        android:left="-2dp"
        android:right="-2dp"
        android:top="-2dp">
        <shape android:shape="rectangle" >
            <stroke
                android:width="0.5dp"
                android:color="@android:color/black" />
        </shape>
    </item>

</layer-list>

To set control's single property like these:

 <EditText
     android:id="@+id/editTextEnterPassword"
     android:layout_width="fill_parent"
     android:layout_height="40dp"
    android:background="@drawable/edittext_bottom_line"
    /> 

I compiled this at my end :

<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true"><layer-list>
                <item android:bottom="-10dp" android:left="-10dp" android:right="-10dp"><shape>
                        <gradient android:angle="270" android:endColor="#a0e0b071" android:startColor="#a0a67637" />

                        <stroke android:width="10dp" android:color="#5c3708" />

                        <corners android:radius="5dp" />

                        <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
                    </shape></item>
            </layer-list></item>
        <item android:state_enabled="true"><layer-list>
                <item android:bottom="-10dp" android:left="-10dp" android:right="-10dp"><shape android:shape="rectangle">
                        <gradient android:angle="270" android:endColor="#a0a67637" android:startColor="#a0e0b071" />

                        <stroke android:width="10dp" android:color="#5c3708" />

                        <corners android:radius="5dp" />

                        <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
                    </shape></item>
            </layer-list></item>

    </selector>

Create a layer list with item as below

<item android:bottom="-1dp"
    android:left="-2dp"
    android:right="-2dp"
    android:top="-2dp">
    <shape android:shape="rectangle" >
        <stroke
            android:width="2dp"
            android:color="#111111" />
    </shape>
</item>


just add underlinebg.xml in res/drawable

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

    <item android:bottom="-1dp"
        android:left="-2dp"
        android:right="-2dp"
        android:top="-2dp">
        <shape android:shape="rectangle" >
            <stroke
                android:width="2dp"
                android:color="@color/drawe_content_color_click" />
        </shape>
    </item>

</layer-list> 

and set the background where ever required. For me i got the solution like [![myoutput!!][1]][1] .I think my answer will helpful for others.

Tags:

Android