Question Detail

How to get rounded corners in the editText (android)

6 years ago Views 3380 Visit Post Reply


Thread Reply

Anonymous

- 6 years ago

There is an easier way than the one written by CommonsWare. Just create a drawable resource that specifies the way the EditText will be drawn:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
 <solid android:color="#FFFFFF"/>
    <corners
     android:bottomRightRadius="15dp"
     android:bottomLeftRadius="15dp"
  android:topLeftRadius="15dp"
  android:topRightRadius="15dp"/>
</shape>

Then, just reference this drawable in your layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<EditText  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="5dip"
    android:background="@drawable/rounded_edittext" />
</LinearLayout>

You will get something like
Image result for corner rounder background

Bili Greed

- 6 years ago

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#ECE9E6"
        android:endColor="#FFFFFF"
        android:angle="270"
        />
    <corners
        android:radius="15dp" />
    <stroke
        android:width="1dip"
        android:color="#ffffff"
        />
    <padding
        android:left="4dp"
        android:top="4dp"
        android:right="4dp"
        android:bottom="4dp"
        />
</shape>

Bili Greed

- 6 years ago

Create XML in Drawable Folder and Use Code

<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>