Change EditText underline color in android xml

Set your choice color through multiple color #codes in editext underline.

Its very difficult to change underline horizontal line color code because what i found attribute is only working on api 21 level so i found another way or you can say alternative option to change editText below underline color via view tag. So here is the complete step by step tutorial for Change edittext underline color in android xml.

android-project-download-code-button

How to Change edittext underline color in android xml.

Code for MainActivity.java file.

package com.android_examples.com.edittextunderlinecolorchange;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

<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"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.edittextunderlinecolorchange.MainActivity" >

 <EditText
 android:id="@+id/editText1"
 android:layout_width="250dp"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:ems="10"
 android:background="@null"
 android:hint="EditText underline change">
 
 <requestFocus />
 </EditText>

 <View
 android:id="@+id/UnderLine"
 android:layout_width="250dp"
 android:layout_height="2dp"
 android:layout_below="@+id/editText1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="2dp"
 android:background="#03f94e" />

</RelativeLayout>

Screenshot:

Change edittext underline color in android xml

Click Here to Download Change edittext underline color in android xml project.

Leave a Reply

Your email address will not be published. Required fields are marked *