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:
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>
I've recreated the behavior of original bottom line. It includes paddings on the edges and same behavior when focused.
expression_edit_text_bgc_selector.xml (set it in android:background)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:drawable="@drawable/expression_edit_text_bgc_focused"/>
<item android:drawable="@drawable/expression_edit_text_bgc_normal"/>
</selector>
expression_edit_text_bgc_focused.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!--<item android:drawable="@color/main_bg_color"/>-->
<item>
<shape>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
<item
android:gravity="bottom"
android:bottom="8dp"
android:left="4dp"
android:right="4dp">
<shape android:shape="rectangle">
<size android:height="2dp"/>
<solid android:color="?colorAccent"/>
</shape>
</item>
</layer-list>
expression_edit_text_bgc_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!--<item android:drawable="@color/main_bg_color"/>-->
<item>
<shape>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
<item
android:gravity="bottom"
android:bottom="8dp"
android:left="4dp"
android:right="4dp">
<shape android:shape="rectangle">
<size android:height="1dp"/>
<solid android:color="?android:colorControlNormal"/>
</shape>
</item>
</layer-list>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With