17

I have this EditText

<EditText
    android:layout_width="match_parent"
    android:layout_height="72dp"
    android:hint="@string/write_message"
    android:textColorHint="@color/primary_color"
    android:ems="10"
    android:imeOptions="actionDone"
    android:inputType="textImeMultiLine"
    android:id="@+id/message_input"
    android:layout_gravity="center_horizontal"
    android:backgroundTint="@color/primary_color"/>

When the box is filled up with user inputted text, it scrolls to the right to make room for more text, I do not like this behavior, and would prefer it if the EditText box expanded upwards when it needs more room? Is there a way to do this? Thanks.

ChristianCuevas
  • 2,672
  • 3
  • 19
  • 24

3 Answers3

35

Yes, this actually involves two things:

  1. Making the EditText accept multi-line input.
  2. Having its height grow as more text lines are added.

Therefore, to achieve this, you need to set up:

android:inputType="textMultiLine"
android:layout_height="wrap_content"

(Be mindful of the difference between textMultiLine and textImeMultiLine).

The full XML snippet would be:

<EditText
    android:layout_width="match_parent"
    android:inputType="textMultiLine"
    android:layout_height="wrap_content"
    android:hint="@string/write_message"
    android:textColorHint="@color/primary_color"
    android:ems="10"
    android:imeOptions="actionDone"
    android:id="@+id/message_input"
    android:layout_gravity="center_horizontal"
    android:backgroundTint="@color/primary_color"/>    
matiash
  • 54,791
  • 16
  • 125
  • 154
2

Use both flags: textMultiLine will wrap your input, and textImeMultiLine will provide a break-line key in your keyboard.

 <EditText
    ...
    android:layout_height="wrap_content"
    android:inputType="textImeMultiLine|textMultiLine"
    ... />
Mardann
  • 1,953
  • 1
  • 16
  • 23
0

In my case I have multiline text, but it showed one line and a keyboard:

enter image description here

Though I have already set android:inputType="textCapSentences|textAutoCorrect|textMultiLine", it didn't help. Then I understood that when the keyboard appears in DialogFragment, it collapses the EditText. See DialogFragment and force to show keyboard to show keyboard when DialogFragment shows.

Then I added a short delay (100-300 ms) before showing the keyboard. Now I have:

enter image description here

In AndroidManifest I set android:windowSoftInputMode="adjustResize" for current activity.

CoolMind
  • 26,736
  • 15
  • 188
  • 224