Android Learner Android Learner - 1 month ago 12
Android Question

how to align icon inside edittext

i want to align icon and text hint inside Edittext. but the icon overlap the left boundry.i want to align it at some distance from left side and the text hint start after a small gap.Here is my code but it is not working properly. For Example like google search option. Please suggest me how to do it. Thanks in advance.

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40sp"
android:layout_marginRight="40sp"
android:layout_marginTop="10sp"
android:background="@drawable/round_edittext"
android:gravity="left"
android:hint="Mobile Number"
android:drawableStart="@drawable/mobile_icon">
</EditText>

Answer

use that code

<EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40sp"
        android:layout_marginRight="40sp"
        android:layout_marginTop="10sp"
               android:padding="5dp"
        android:background="@drawable/round_edittext"
        android:gravity="left"
        android:hint="Mobile Number"
        android:drawableStart="@drawable/mobile_icon">
    </EditText>