How to set line as a background using xml (shape) below to EditText?


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


<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>


<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 ?


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>


<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>


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>


  • Android: Button background XML sometimes loses alpha when setting color filter
  • TextView shadow not showing up in preview - although working on real device
  • Edittext requestFocus() dynamically not working
  • CSS animation do not work for svg in
  • onMeasure() called with EXACTLY and spec size 0
  • I can't show LinearLayout at bottom to scroll view
  • Can I override some attribute of drawable shape?
  • Sticky Footer Below ListView in Android Layout
  • Overlapping ImageView in RelativeView
  • Android custom dialog linearlayout size same as dialogs bg image
  • Background image crashes android
  • Float Label hint (TextInputLayout) not works with Android Data Binding
  • Android Custom dialog inflating from layout - alignment issue
  • Recreate Apple Watch fitness tracker ‘progress’ bar - gradient on CAShapeLayer stroke
  • EditText ignores the ImeActionLabel
  • Translate animation to correct position in Android
  • Toolbar shifts up, when soft keyboard appears
  • Loop animation drawable
  • Gray line inside cardview :)?
  • Express JS Display Data By ID
  • Wrapping text in spinner android
  • Running jasmine tests for a component with NgZone dependency
  • How to resolve permission denied maybe missing internet permission?
  • WPF Template Binding in ToggleButton UserControl
  • D3 get axis values on zoom event
  • Access variable of ScriptContext using Nashorn JavaScript Engine (Java 8)
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • Code in Job's Script Block after Start-Process Does not Execute
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • How reduce the height of an mschart by breaking up the y-axis
  • How to set/get protobuf's extension field in Go?
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • How to show dropdown in excel using jrxml (jasper api)?
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Android Google Maps API OnLocationChanged only called once
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy