Search code examples
androidxmlandroid-edittextdrawable

Place Icon at Top Left Corner in Multiline EditText


How Do I place icon at top left corner in multiline EditText, here is what I am using :

<EditText
        android:id="@+id/editComments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:paddingTop="10dp"
        android:paddingBottom="20dp"
        android:paddingRight="10dp"
        android:layout_margin="10dp"
        android:hint="Comments"
        android:inputType="textMultiLine"
        android:lines="4"
        android:drawablePadding="20dp"
        android:minLines="4"
        android:gravity="top|left"
        android:drawableLeft="@drawable/comment"
        android:maxLines="4" />

I am getting icon as left aligned but in center not at top


Solution

    1. You have to understand what you are using. There is no such thing as android:setToTop in your editText options - that's why it does not align to the top; android:paddingTop is about something else.
    2. It depends on which layout are you using - the best one for your problem is RelativeLayout, which uses android:layout_alignTop.

    I strongly suggest that you should read more about layouts which can help you understand how it works and what are you doing - copy & paste the code doesn't help every time!