Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Edittext(Multiline) leftdrawable on top position

I am using Edittext with textMultiLine attributes. I got edittext text on top position using android:gravity="top". But I cannot get android:drawableLeft="@drawable/ic_message" on top position.

enter image description here

I want android:drawableLeft="@drawable/ic_message" on top position(left of the Message text)

Edits

My Edittext xml is as below:

<EditText
    android:id="@+id/edtContactMessage"
    style="@style/styleRoundedEdittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/tendp"
    android:drawableLeft="@drawable/ic_message"
    android:gravity="top"
    android:hint="@string/strMessage"
    android:imeOptions="actionDone"
    android:inputType="textMultiLine"
    android:lines="5"
    android:maxLength="500"
    android:minHeight="120dp"
    android:scrollbars="vertical"
    android:singleLine="false" />
like image 441
pRaNaY Avatar asked Nov 19 '15 13:11

pRaNaY


1 Answers

It is not possible to set the left drawable on a EditText at the top position like that, you would need to wrap your EditText inside a parent layout where you can place a ImageView that draws the icon at this position instead.

Here is an example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@android:drawable/edit_text"
android:orientation="horizontal">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:src="@android:drawable/ic_menu_send"
    android:scaleType="fitStart"
    android:contentDescription="message icon"
    />

<EditText
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:background="@null"
    android:padding="4dp"
    android:text="Message"
    android:inputType="textMultiLine"
    android:gravity="top"
    android:layout_weight="1" />

</LinearLayout>
like image 113
TouchBoarder Avatar answered Sep 27 '22 22:09

TouchBoarder