Search code examples
androidbackgroundandroid-edittexttextfieldunderline

Android EditText background with line inside


i'm creating background for my EditText , and i want to add line under the text.

My background code:

<item android:state_pressed="true" android:state_focused="true">
    <shape>
        <solid android:color="#10FFFFFF" />
        <corners android:radius="5dp" />
    </shape>
</item>

How can i add line inside the shape?

Preview from graphics project: enter image description here


Solution

  • Try this (the answer is found by editing the post Krylez posted). I have tested this and it works. Create a XML in the drawable folder with, and set the colors as you desire. Then set is as a background for the EditText

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <solid android:color="@android:color/transparent" /> <!--background color of box-->
            </shape>
        </item>
    
        <item
            android:top="-2dp"
            android:right="-2dp"
            android:left="-2dp">
            <shape>
                <solid android:color="@android:color/transparent" />
                <stroke
                    android:width="1dp"
                    android:color="#000000" />  <!-- color of stroke -->
            </shape>
        </item>
    </layer-list>