在 Android 中的 EditText 左侧设置图像 [英] Set Image on Left side of EditText in Android

查看:48
本文介绍了在 Android 中的 EditText 左侧设置图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个联系表单,我想在其中添加一些图标到我的编辑文本中以获得更好的外观.我想创建如下所示的 EditText.

I am having one contact form in which I would like to add some icons to my edit text for a better look. I want to create EditText something like below.

我有如下所示的 EditText.我得到了类似的结果.我希望图像绝对在左侧,就像上图一样.我知道 EditText 内部使用的是九个补丁图像,我认为这就是结果有些不同的原因.有谁知道如何解决这个问题?

I have EditText like below. And I got the result something like. I want the image to be absolutely on the left side as it is in the above image. I know that internally EditText is using Nine Patch image and i think that is why the result is some what different. Can anyone know how to resolve this?

<EditText
            android:id="@+id/name"
            android:layout_width="fill_parent"
            android:layout_height="51dip"
            android:hint="@string/name"
            android:inputType="text"
            android:drawableLeft="@drawable/name_icon_edittext" />

推荐答案

不要使用 android:drawableLeft="@drawable/name_icon_edittext",而是为name_icon.这样,您可以更好地控制将其放置在 layout

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

注意:我假设你的 layoutRelativeLayout

这篇关于在 Android 中的 EditText 左侧设置图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆