Search code examples
androidactionandroid-edittextword-wrapmultiline

Android EditText: Done instead of Enter or Word Wrap instead of Multi Line


I have a multiple line EditText that does not permit line returns. Right now I am replacing returns with some spaces as soon as they click save. Is there any way I can replace the on screen enter button with a Done button? (like it is for single line EditText)

I am aware that I should still strip out returns (\r\n|\r|\n) because the on screen keyboard is not the only way to add them.

Here is my current XML

<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
          android:minLines="3" android:gravity="left|top"
          android:inputType="textMultiLine|textAutoCorrect|textCapSentences"
          android:imeOptions="actionDone" />

Solution

  • android:inputType="textEmailAddress|textEmailSubject"
    

    You need to set the input type as email address or email subject. Either one will give you your desired result. shouldAdvanceFocusOnEnter() is a private method in TextView which determines whether to enter a new line or move focus to next field.