How to change EditText bottom line color in Android
Hi guys ! In this tutorial i will show you how to change editText bottom line color.This can be done in two ways.The first way is the easy way and another way is little bit complex but it gives you more control over UI.
First the easy way-
The backgroundTint attribute will help you to add a tint(shade) to the background. You can provide a color value for the same in the form of - "#rgb", "#argb", "#rrggbb", or "#aarrggbb".
Second Way- In this method we will create an xml LayerDrawable which will be used as a background.
A LayerDrawable is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top. Each drawable is represented by an- element inside a single
element.
The LayerList can be used to draw multiple other drawables (shapes, images, etc) and position them in relationship to one another. The layers are placed on top of one another by default with the last item being drawn on the top. Layers can then have their coordinates shifted using the left, right, top, and bottom properties.
activity_main.xml
First the easy way-
android:backgroundTint="#ff1e0c"
The backgroundTint attribute will help you to add a tint(shade) to the background. You can provide a color value for the same in the form of - "#rgb", "#argb", "#rrggbb", or "#aarrggbb".
Second Way- In this method we will create an xml LayerDrawable which will be used as a background.
A LayerDrawable is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top. Each drawable is represented by an
The LayerList can be used to draw multiple other drawables (shapes, images, etc) and position them in relationship to one another. The layers are placed on top of one another by default with the last item being drawn on the top. Layers can then have their coordinates shifted using the left, right, top, and bottom properties.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.shankhajana.tutorial.MainActivity"> <EditText android:id="@+id/input_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginLeft="@dimen/activity_vertical_margin" android:layout_marginRight="@dimen/activity_vertical_margin" android:layout_marginTop="76dp" android:background="@drawable/edittext_bg" android:hint="Enter Your Name" android:padding="10dp" /> <!--This is optional.Not required for this tutorial--> <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="400dp" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_marginTop="319dp" android:src="@drawable/img" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <!-- Draw a 2dp width border around shape --> <stroke android:color="#ff1e0c" android:width="2dp" /> </shape> </item> <!-- Overlap the left, top and right border using background color --> <item android:bottom="2dp" > <shape android:shape="rectangle"> <solid android:color="#fffbce"/> </shape> </item> </layer-list>
great tutorial!
ReplyDeleteThanks!