Add rounded corners border to edittext android using xml

Create EditText with rounded corners border.

EditText can be easily modified through activity_main.xml file via adding another layout file and set that rounded_border_edittext.xml file to editText background. This type of editText looks like most of web sites applications data submission forms. So here is the complete step by step tutorial for Add rounded corners border to edittext android using xml.

android-project-download-code-button

How to Add rounded corners border to edittext android using xml.

Code for MainActivity.java file.

package com.example.edittextwithroundedborder_android_examples.com;
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.example.edittextwithroundedborder_android_examples.com.MainActivity"
 android:background="#ffffff" >

 <EditText
 android:id="@+id/editText1"
 android:layout_width="wrap_content"
 android:layout_height="55dp"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:ems="10"
 android:hint="EditTextRoundedBorder"
 android:background="@layout/rounded_border_edittext"
 android:gravity="center" >

 <requestFocus />
 </EditText>

</RelativeLayout>

 

Code for rounded_border_edittext.xml file.

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
 <shape android:shape="rectangle">
 <solid android:color="#ffffff"/>
 <corners android:radius="10dp" />
 <stroke
 android:width="2dp"
 android:color="#3bbdfa"
 />
 </shape>
</item>
</selector>

Screenshot:

Add rounded corners border to edittext android using xml

Click Here To Download Add rounded corners border to edittext android using xml project.

3 Comments

  1. It is giving me error of URL is not registered. Can u try to figure it out and tell me the solution regarding problem. Thanks

  2. android:background=”@layout/ ?

Leave a Reply

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