Set Image on Left side of EditText in Android

人走茶凉 提交于 2019-11-28 08:26:33
Tomer Mor

Instead of using android:drawableLeft="@drawable/name_icon_edittext", create separateImageView for the name_icon. This way you have more control on placing it on the layout

Note: I am assuming your layout is RelativeLayout

if you want to add some space between you text and image then use'drawablePadding' property in xml

android:drawablePadding="10dp"

here is complete example how to use in edittext in xml file

             <EditText
                android:id="@+id/edittext"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/ic_left"
                android:drawablePadding="10dp" />
Milind App

You can use android:drawablePadding="10dp" property in the xml file. There's no need to create separate imagview for the icon.

A bit old, but for future reference maybe:

I would do a 9-patch image myself with the appearance you want, keeping the proportions and all but the icon, so you can add it yourself (and reuse the background) with drawableLeft property of EditText. That way only the middle part of the image will be stretched but the rest will stay the same.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!