Remove EditText underline programmatically in android

Hide EditText under border through MainActivity.java programming file.

On my this tutorial i am hiding edittext underline using setBackgroundDrawable() function on button click event so when application user clicks on button then underline hiding function will called because it defined in on click listener. So here is the complete step by step tutorial for Remove EditText underline programmatically in android.

android-project-download-code-button

How to Remove EditText underline programmatically in android.

Code for MainActivity.java file.

 package com.android_examples.com.edittextremoveunderline;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

 EditText DisableEditText;
 Button DisableButton;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 DisableEditText = (EditText)findViewById(R.id.editText1);
 DisableButton = (Button)findViewById(R.id.button1);
 
 
 DisableButton.setOnClickListener(new View.OnClickListener() {
 
 @SuppressWarnings("deprecation")
 @Override
 public void onClick(View v) {
 
 DisableEditText.setBackgroundDrawable(null);
 }
 });
 }
}

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.edittextremoveunderline.MainActivity" >

 <EditText
 android:id="@+id/editText1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:ems="10"
 android:hint="EditText programmatically" >

 <requestFocus />
 </EditText>

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/editText1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="16dp"
 android:text="Click Here to Hide EditText underline programmatically" />

</RelativeLayout>

Screenshot:

Remove EditText underline programmatically in android

Click Here To Download Remove EditText underline programmatically in android project.