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.
For a URI you could use:
Otherwise
android:inputType="textPersonName"
as mentioned above works for other EditText such user name, etc.Here is the solution....
Usage in java class
Simply add
to your EditText
Try this:
This one works for me:
It shows a smiley instead of the Enter key.
Here's a more correct answer that does not display the enter key on the IME keyboard:
Also, you may replace
setSingleLine(true)
with either, an explicitandroid:inputType
on the XML layout file, orsetInputType(InputType.*)
on code – in which, the input type used, is anything that you know restricts the input to single lines only (i.e., anything that callssetSingleLine(true)
implicitly already).Explanation:
What
setSingleLine(true)
does is callingsetHorizontallyScrolling(true)
andsetLines(1)
implicitly, alongside with altering some IME keyboard settings to disable the enter key.In turn, the call to
setLines(1)
is like callingsetMinLines(1)
andsetMaxLines(1)
in one call.Some input types (i.e., the constants from
InputType.TYPE_*
) callssetSingleLine(true)
implicitly, or at least achieves the same effect.Conclusion:
So to achieve what the OP wants, we simply counter those implicit settings by reverting those implicit calls.