Gap between left drawable and text in a EditText

AndroidAndroid LayoutAndroid Edittext

Android Problem Overview


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
	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" />

enter image description here

Android Solutions


Solution 1 - Android

You should add android:drawablePadding attribute to your EditText. Example layout with 10dp drawable padding:

<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" />

Solution 2 - Android

to move the drawable icon left or right use android:paddingLeft or android:paddingRight do not use android:drawablePadding

Solution 3 - Android

When you set any drawable using android:drawableLeft / android:drawableRight property then you can add space or gap using android:drawablePadding property.

<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" />

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionN SharmaView Question on Stackoverflow
Solution 1 - AndroiderakitinView Answer on Stackoverflow
Solution 2 - AndroidGentleView Answer on Stackoverflow
Solution 3 - AndroidHaresh ChhelanaView Answer on Stackoverflow