14

I saw many related discussions but didn't find a suitable solution. What I need to do is to create a black border on the bottom side of an EditText widget. Is that possible?

Manjeet Brar
  • 914
  • 1
  • 9
  • 27
  • you can use image background, first thing that poped in my mind...looking for other solutions also – MSA Aug 25 '14 at 07:47
  • possible duplicate of [Is there an easy way to add a border to the top and bottom of an Android View?](http://stackoverflow.com/questions/1598119/is-there-an-easy-way-to-add-a-border-to-the-top-and-bottom-of-an-android-view) – Simas Aug 25 '14 at 07:47

6 Answers6

68

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"
    /> 
Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
Dhruv Raval
  • 4,946
  • 3
  • 29
  • 34
11

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>
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
6

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.

Subhalaxmi
  • 5,687
  • 3
  • 26
  • 42
3

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>

Anmol Juneja
  • 325
  • 1
  • 9
2

you can create one xml file like follow:

<item>
    <shape android:shape="rectangle" >
        <solid android:color="@color/orange" />
    </shape>
</item>
<item android:bottom="4dp">
    <shape android:shape="rectangle" >
        <size android:height="4dp" />

        <solid android:color="@color/green3" />
    </shape>
</item>

then set this file as your background

Shayan Pourvatan
  • 11,898
  • 4
  • 42
  • 63
0
<?xml version="1.0" encoding="utf-8" `enter code here`?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:left="2dp" android:right="-2dp"
        android:top="-2dp" android:bottom="2dp" >
        <shape android:shape="rectangle">
            <stroke android:color="@android:color/black" android:width="2dp">

            </stroke>
        </shape>
    </item>
</layer-list>