Multi-Line Edittext with Done Action Button

How to implement Multiline EditText with ActionDone button (without Enter button)

Finally, after searching here for similar threads I have found solution. Just need to add these lines on your Activity/Fragment:

editText.setHorizontallyScrolling(false);
editText.setMaxLines(Integer.MAX_VALUE);

For some reason it doesn't work if you apply exact same setting from xml. You should do it programmatically.

There is also another possible solution - derive from EditText and apply EditorInfo.IME_ACTION_DONE manually. But for me first solution looks simpler.

EditText multiline with next view button instead of new line button

I think what you are looking for is the same as in this answer:

In code:

editText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);

and in xml:

android:inputType="textMultiLine"

Multiline text input with a Done/Submit button on keyboard on Android

No it's not possible. With multiline input on Android, the enter key is the only way to put a line break.

See also Multi-line EditText with Done action button

Why does Android multiline EditText with android:imeOptions=actionNext work in Google Keep?

You can set imeOptions=actionNext in XML & at runtime setRawInputType to TYPE_TEXT_FLAG_MULTI_LINE. This way you can achieve this behavior.

According to docs setRawInputType is used for:

Directly change the content type integer of the text view, without
modifying any other state.

Example:

XML:

 <EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Activity#onCreate:

binding.editText.setRawInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
or InputType.TYPE_TEXT_FLAG_MULTI_LINE)

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


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.



Related Topics



Leave a reply



Submit