Ruslan Ruslan - 1 year ago 149
Android Question

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

I have EditText which is used for entering contents on messages (emails, sms). I want message to be immediately posted on ActionDone button click. I use following code for this:

message.setOnEditorActionListener((textView, i, keyEvent) -> {
switch (i) {
case EditorInfo.IME_ACTION_DONE:
if (messageCanBePosted()) {
return true;
} else {
return false;
return false;

But also I want this message field to be multiline, like in any other messenger apps. I can achieve it with this line:


The problem is that after adding this line ActionDone button starts acting like Enter button. So my callback for catching
is never called. So each time user press that button cursor moves to new line instead of posting message.

How can I keep both multiline behavior of EditText (ability to show text on multiple lines) and ActionDone button?

Answer Source

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


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download