3

Can anybody tell me how to create an editable textbox with rounded corners in android?

I tried with this code but it's not working:

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

Thanks

Illidanek
  • 996
  • 1
  • 18
  • 32
mohan
  • 13,035
  • 29
  • 108
  • 178
  • Before OS 2.3, android edit text used to have a rounded cornered background. So what you can do is, copy the older background image in your res folder and then set it manually in your xml file. – mudit Apr 04 '11 at 12:03

4 Answers4

6

Just create an xml file in your drawable folder name as round_corner.xml.And add this following code.

   <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >

        <corners
            android:bottomLeftRadius="3dp"
            android:bottomRightRadius="3dp"
            android:radius="3dp"
             />
        <solid
            android:color="@android:color/white"/>

    </shape>

At Last you add this xml in background property of your Edittext as follows:-

<EditText
   android:id="@+id/ed1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/round_corner"
 />

Done..Definitely it works..

Born To Win
  • 3,319
  • 3
  • 19
  • 27
6

Hey have a look about the problem in this discussion : How to create EditText with rounded corners? ..I am sure it will surely gonna help you.

Community
  • 1
  • 1
Kartik Domadiya
  • 29,868
  • 19
  • 93
  • 104
0

Use This Code

 <?xml version="1.0" encoding="utf-8"?>
 <!-- res/drawable/rounded_edittext.xml --> 
<shape xmlns:android="schemas.android.com/apk/res/android"; android:shape="rectangle" android:padding="10dp"> <solid android:color="#FFFFFF" > 

<corners android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" /> 

</shape>
Harinder
  • 11,776
  • 16
  • 70
  • 126
-1
<?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>
Chandrahasan
  • 1,991
  • 24
  • 26