How can I set a row as background using the xml (shape) below in EditText?
I want to set line as background below EditText using xml form, but when I set it set line to center
I want like below
but when i set the form below
extract / line.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:height="4dp"
android:color="@color/crabfx_dark_gray" />
</shape>
activity_main.xml
<EditText
android:id="@+id/edt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:layout_margin="20dp"
android:background="@drawable/line"/>
I got below result
- any solution?
+3
source to share
3 answers
Try this, I hope you get a perfect solution.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="@color/gray" />
</shape>
</item>
<!-- main color -->
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp">
<shape>
<solid android:color="@color/white" />
</shape>
</item>
<!-- draw another block to cut-off the left and right bars -->
<item android:bottom="1dp">
<shape>
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>
Or try this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="@color/gray" />
</shape>
</item>
<item
android:bottom="1px"
android:left="0px">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
+7
source to share
Try this way, hope it helps you solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:id="@+id/edt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"/>
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/line"/>
<EditText
android:id="@+id/edt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"/>
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/line"/>
</LinearLayout>
0
source to share