user724861
user724861

Reputation: 1074

Android EditText not expanding when hitting enter

I have a EditText look like this in my layout xml and it's not expanding when the user hit enter

<EditText 
        android:layout_height="40dp"
        android:layout_width="fill_parent"
        android:gravity="top"
        android:maxLines="10"
        android:minHeight="40dp"
        android:id="@+id/edSearch"
        android:layout_toLeftOf="@+id/btnSearch"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:hint="City..."
        />

but when i changed android:layout_height="40dp" to android:layout_height="wrap_content" the the edittext is able to expand as the user hit enter.

how I can keep my EditText expanding while keeping this line android:layout_height="40dp"

Thanks

Upvotes: 1

Views: 2022

Answers (4)

Asheesh
Asheesh

Reputation: 581

Try this

<EditText 
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:gravity="Top"
        android:maxLines="10"
        android:minHeight="40dp"
        android:id="@+id/edSearch"
        android:layout_toLeftOf="@+id/btnSearch"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:inputType="textMultiLine"
        android:hint="City..."
        />

Hope this will work

Upvotes: 2

Umar Qureshi
Umar Qureshi

Reputation: 6115

I'm using following code and it's working great. to set minimum height instead of setting layout_height to 40dp set it wrap_content and set attribute of minLines to achieve this as show below in code example

  <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textMultiLine"
        android:minLines="4"
        android:maxLines="10"
         />

Upvotes: 1

Sachin Gadagi
Sachin Gadagi

Reputation: 749

Set android:multiline="true" along with android:gravity="left|top"

Upvotes: 0

Cheerag
Cheerag

Reputation: 435

Set property android:multiline="true". hope this will help you.

Upvotes: 0

Related Questions