How to add border only at the bottom of EditText?

I saw a lot of related discussions, but did not find a suitable solution. What I need to do is create a black border at the bottom of the EditText widget. Is it possible?

+5
source share
5 answers

I compiled this at the end:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><layer-list> <item android:bottom="-10dp" android:left="-10dp" android:right="-10dp"><shape> <gradient android:angle="270" android:endColor="#a0e0b071" android:startColor="#a0a67637" /> <stroke android:width="10dp" android:color="#5c3708" /> <corners android:radius="5dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape></item> </layer-list></item> <item android:state_enabled="true"><layer-list> <item android:bottom="-10dp" android:left="-10dp" android:right="-10dp"><shape android:shape="rectangle"> <gradient android:angle="270" android:endColor="#a0a67637" android:startColor="#a0e0b071" /> <stroke android:width="10dp" android:color="#5c3708" /> <corners android:radius="5dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape></item> </layer-list></item> </selector> 
+7
source

just create one edittext_bottom_line.xml file in drawable folder in res

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:bottom="1dp" android:left="-2dp" android:right="-2dp" android:top="-2dp"> <shape android:shape="rectangle" > <stroke android:width="0.5dp" android:color="@android:color/black" /> </shape> </item> </layer-list> 

To set one control property as follows:

  <EditText android:id="@+id/editTextEnterPassword" android:layout_width="fill_parent" android:layout_height="40dp" android:background="@drawable/edittext_bottom_line" /> 
+45
source

just add underlinebg.xml to res / drawable

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:bottom="-1dp" android:left="-2dp" android:right="-2dp" android:top="-2dp"> <shape android:shape="rectangle" > <stroke android:width="2dp" android:color="@color/drawe_content_color_click" /> </shape> </item> </layer-list> 

and set the desired background. For me, I got a solution like [! [Myoutput !!] [1]] [1]. I think my answer will be useful to others.

+3
source

you can create one XML file, for example:

 <item> <shape android:shape="rectangle" > <solid android:color="@color/orange" /> </shape> </item> <item android:bottom="4dp"> <shape android:shape="rectangle" > <size android:height="4dp" /> <solid android:color="@color/green3" /> </shape> </item> 

then set this file as background

+2
source
 <?xml version="1.0" encoding="utf-8" `enter code here`?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:left="2dp" android:right="-2dp" android:top="-2dp" android:bottom="2dp" > <shape android:shape="rectangle"> <stroke android:color="@android:color/black" android:width="2dp"> </stroke> </shape> </item> </layer-list> 
0
source

Source: https://habr.com/ru/post/1201056/


All Articles