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

荒凉一梦 提交于 2019-11-30 04:51:07

Use

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

and in XML:

android:inputType="textMultiLine"

Source : Multi-line EditText with Done action 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.

Noman Rafique

Continuing Ruslan's answer. The trick worked but there is one more thing that you need to take care of in XML.

EditText should have input type text otherwise actionDone won't work. Default input type of EditText does allow user to input line breaks so inputType should be set to text i.e.

android:inputType="text"
//And of course
android:imeOptions="actionDone"

And in your java class you need to add:

editText.setHorizontallyScrolling(false);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!