
Question:
I want to set the line as background below EditText using shape xml but when I set it line set on center
I want like below
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/7X0fO.png" data-original="https://i.stack.imgur.com/7X0fO.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
but when I set the shape below
drawable/line.xml
<blockquote><?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>
</blockquote>
activity_main.xml
<blockquote><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"/>
</blockquote>
I got below output
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/9paD3.png" data-original="https://i.stack.imgur.com/9paD3.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
is any solution ?
Answer1:Try this one i hope you will get 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>
Answer2:<strong>Try this way,hope this will help you to solve your problem.</strong>
<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>
Answer3:Try this code just below your EDIT_text:
<View
android:id="@+id/dividerView"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#191919"
>
</View>