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
- 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.
- 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!
use this code
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/left_drawer"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#FFA500">
<EditText
android:id="@+id/editComments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Comments"
android:inputType="textMultiLine"
android:padding="20dp"
android:lines="4"
android:drawablePadding="20dp"
android:minLines="4"
android:gravity="top|left"
android:maxLines="4" />
<ImageButton
android:layout_width="20dp"
android:layout_gravity="left"
android:src="@drawable/comment"
android:layout_height="20dp" />
</FrameLayout>
Try this,
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_below="@+id/rlHeader"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_lock"
android:layout_gravity="top"/>
<EditText
android:id="@+id/editComments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Comments"
android:inputType="textMultiLine"
android:lines="4"
android:textColor="@android:color/white"
android:textColorHint="@android:color/white"
android:layout_marginLeft="10dp"
android:minLines="4"
android:gravity="top|left"
android:maxLines="4" />
</LinearLayout>