Here's a more correct answer that does not display the enter key on the IME keyboard:
// IMPORTANT, do this before any of the code following it
myEditText.setSingleLine(true);
// IMPORTANT, to allow wrapping
myEditText.setHorizontallyScrolling(false);
// IMPORTANT, or else your edit text would wrap but not expand to multiple lines
myEditText.setMaxLines(6);
Also, you may replace setSingleLine(true)
with either, an explicit android:inputType
on the XML layout file, or setInputType(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 calls setSingleLine(true)
implicitly already).
Explanation:
What setSingleLine(true)
does is calling setHorizontallyScrolling(true)
and setLines(1)
implicitly, alongside with altering some IME keyboard settings to disable the enter key.
In turn, the call to setLines(1)
is like calling setMinLines(1)
and setMaxLines(1)
in one call.
Some input types (i.e., the constants from InputType.TYPE_*
) calls setSingleLine(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.