12

I am trying to customize the look of an EditText but I am failing to do so... I would like to have the textfield in rounded borders with a graphic icon to the left (so the icon would be inside the borders too, next to the edittext). Could somebody please explain me how I could achieve this? Do I need to draw the border as a shape or is there some property for this? Thanks a lot!

Fygo
  • 4,555
  • 6
  • 33
  • 47
  • 1
    For rounded corners this will work for you http://stackoverflow.com/questions/3646415/how-to-create-edittext-with-rounded-corners have a look – vinay kumar Jan 30 '13 at 06:59
  • For icon to the left side of the edit text, you can group the icon and edit text in a single layout in my sense linear layout with horizontal orientation work to this. – vinay kumar Jan 30 '13 at 07:01
  • @Fygo I may be mistaken but your Q sounds to me as if you want to achieve this for all EditText fields in your app, or at least to those "of a kind". If my assumption is right, you'll want to create a style from the other suggestions and simply apply that. – class stacker Jan 30 '13 at 07:14
  • Thanks for the suggestions, guys. I will actually need this only for 2 fields so no theme is necessary. However, I will definitely check out asap how to create custom themes. (I am quite a noob at the moment, my first day playing with the android sdk) – Fygo Jan 30 '13 at 07:46

2 Answers2

9

Try like this

                <EditText
                    android:id="@+id/rLastName"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/editbox"
                    android:hint="@string/lname"
                    android:padding="5dip"
                    android:singleLine="true"
                    android:textColor="#999999"
                     android:textSize="14dip"                          
                    android:drawableLeft="@drawable/ic_launcher" /> 

Drawable left the icon will be set in left side

enter image description here

You can try this link for rounded corners link

Community
  • 1
  • 1
Janmejoy
  • 2,721
  • 1
  • 20
  • 38
  • Thanks a lot, works perfect! So if I understand it correctly, once I assign the 'background' property it also removes the blue line under the EditText from the theme? – Fygo Jan 30 '13 at 07:40
1

How to create EditText with rounded corners?
And
http://alinberce.wordpress.com/2012/02/20/android-edittext-with-custom-font-and-clear-button/

Community
  • 1
  • 1
Anukool
  • 5,301
  • 8
  • 29
  • 41
  • 1
    Thanks for this, even if I wanted to accomplish this purely by XML, it was an interesting example! – Fygo Jan 30 '13 at 07:42