How to make Android EditText expand vertically when full
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"
... />
Yes, this actually involves two things:
- Making the
EditText
accept multi-line input. - 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"/>