How do I make an EditText on Android such that the user may not enter a multi-line text, but the display is still multi-line (i.e. there is word-wrap instead of the text going over to the right)?
It's similar to the built-in SMS application where we can't input newline but the text is displayed in multiple lines.
You can set it from the xml like this:
don't forget
android:inputType="text"
, if you don't set it, it doesn't work. I don't know why though. Also don't forget to changemaxLines
to your preferred value.I would subclass the widget and override the key event handling in order to block the
Enter
key:The accepted answer worked so well until I copied text with line-breaks into into the EditText. So I added onTextContextMenuItem to monitor the paste action.
You can change the action button from code
Xml
Property in XML