Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Custom EditText with Icon

I'm trying to learn Android and its UI. Would it be possible to create an EditText like my design below?

EditText Design

Which should include:

  • Small Icon in the left which should be changeable when an event has occured (guessing this is done programitically)
  • The right border edge next to the icon
  • Thick stroke when hovered

Can probably work out how to change the icon and thick stroke when an event has occured but do not know how to code the icon with the right border edge inside the editText smoothly. Help!

like image 846
MathanMV Avatar asked Mar 06 '13 19:03

MathanMV


1 Answers

you can use

android:drawableLeft="@drawable/your_drawable"

on your EditText in xml.

And from java you can change it like this

Drawable img = getContext().getResources().getDrawable( R.drawable.your_other_drawable );
txtVw.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null );

You'll have to make your own background resources if you want the edit box to have the same rounded/square corners as it does in your example image.

like image 71
FoamyGuy Avatar answered Sep 27 '22 16:09

FoamyGuy