1

I am building a text area in my APP using a TextInputLayout and its multiline property to let the users write more than 1 line, I am building it programatically (no xml)

TextInputLayout textInputLayout = new TextInputLayout(context);
textInputLayout.setLayoutParams(new TextInputLayout.LayoutParams(TextInputLayout.LayoutParams.MATCH_PARENT, TextInputLayout.LayoutParams.WRAP_CONTENT));

TextInputEditText field = new TextInputEditText(context);
field.setText(text);
field.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
field.setLayoutParams(new TextInputLayout.LayoutParams(TextInputLayout.LayoutParams.MATCH_PARENT,(int) (100 * dp)));
textInputLayout.addView(field);
myLinearLayout.addView(textInputLayout); // add text to layout

The code above makes my textarea, but is not showing the line break button, it shows a submit button instead.

This is the current result:

enter image description here

This is the expected result (from another app):

enter image description here

Which property I have to add to show the line break button like the second image?

stramin
  • 2,183
  • 3
  • 29
  • 58

1 Answers1

2

How to get the keyboard to show a return key?

Try setting IMEOptions as None.

field.setImeOptions(EditorInfo.IME_ACTION_NONE);

Also check if the EditText has become SingleLine that also causes the done button to appear.

Shashank Degloorkar
  • 3,151
  • 4
  • 32
  • 50
  • I tried and the "return" button appeared, but when I press it, is inserting spaces instead of line breaks, I wonder if is like you said (EditText turned into a SingleLine?) – stramin Oct 07 '19 at 18:25
  • 2
    Ok, I figured it out, I had to add `InputType.TYPE_CLASS_TEXT`, I going to edit the question, Thank you! – stramin Oct 07 '19 at 18:30
  • Great. Even I didnt know that. Good to know. :) This could work in other scenarios. field.setLines(10); Will give 10 lines to the user. But your solution looks neat. – Shashank Degloorkar Oct 07 '19 at 18:30