Android EditText 中左侧可绘制对象和文本之间的间隙
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23607945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gap between left drawable and text in a EditText
提问by N Sharma
Hello I am setting drawable to left end in the EditText
using property android:drawableLeft="@drawable/email_drawable"
, I am trying this it set the drawable perfectly but it is not setting gap between left drawable and text. Could you please help me to achieve this ?
你好,我在EditText
using 属性中将 drawable 设置为左端android:drawableLeft="@drawable/email_drawable"
,我正在尝试它完美地设置了 drawable,但它没有设置 left drawable 和文本之间的间隙。你能帮我实现这个目标吗?
<EditText
android:id="@+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/sign_up_edittext_vertical_top_margin"
android:drawableLeft="@drawable/email_drawable"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:singleLine="true" />
回答by erakitin
You should add android:drawablePadding
attribute to your EditText
. Example layout with 10dp
drawable padding:
您应该将android:drawablePadding
属性添加到您的EditText
. 带有10dp
可绘制填充的示例布局:
<EditText
android:id="@+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/sign_up_edittext_vertical_top_margin"
android:drawableLeft="@drawable/email_drawable"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:drawablePadding="10dp"
android:singleLine="true" />
回答by Gentle
to move the drawable icon left or right use android:paddingLeft
or android:paddingRight
do not use android:drawablePadding
向左或向右移动可绘制图标使用android:paddingLeft
或android:paddingRight
不使用android:drawablePadding
回答by Haresh Chhelana
When you set any drawable using android:drawableLeft
/ android:drawableRight
property then you can add space or gap using android:drawablePadding
property.
当您使用android:drawableLeft
/android:drawableRight
属性设置任何可绘制对象时,您可以使用android:drawablePadding
属性添加空间或间隙。
<EditText
android:id="@+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/sign_up_edittext_vertical_top_margin"
android:drawableLeft="@drawable/email_drawable"
android:imeOptions="actionNext"
android:drawablePadding="5dp" // set your padding or gap size here
android:inputType="textEmailAddress"
android:singleLine="true" />