How to set transparent background to Edittext using setBackgroundColor(Color.TRANSPARENT) method in android.
In this tutorial we are dynamically changing the EditText default background to transparent from MainActivity.java programming file. So here is the complete step by step tutorial for How to make transparent edittext in android programmatically.
How to make transparent edittext in android programmatically.
Code for MainActivity.java file.
package com.transparentedittextusingprogrammatically;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText edt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt = (EditText)findViewById(R.id.editText1);
edt.setBackgroundColor(Color.TRANSPARENT) ;
}
}
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.transparentedittextusingprogrammatically.MainActivity" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:hint="Transparent Programmatically" > <requestFocus /> </EditText> </RelativeLayout>
Screenshot: