Reputation: 2692
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.
Upvotes: 17
Views: 21062
Reputation: 28748
In my case I have multiline text, but it showed one line and a keyboard:
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:
In AndroidManifest
I set android:windowSoftInputMode="adjustResize"
for current activity.
Upvotes: 0
Reputation: 2143
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"
... />
Upvotes: 2
Reputation: 55340
Yes, this actually involves two things:
EditText
accept multi-line input.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"/>
Upvotes: 35