I am trying to create a multiline EditText by code. This is what I use:
EditText txt = new EditText(this); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f); txt.setLayoutParams(lp); txt.setSingleLine(false); txt.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
But it is still in one single line.
setLayoutParams(lp); txt. setSingleLine(false); txt. setInputType(InputType. TYPE_TEXT_FLAG_MULTI_LINE);
This tag makes the EditText be at most x many lines tall as specified as value. It accepts an integer value. Note : For multiline EditText by default the cursor and hint text is displayed in the center, you can use android:gravity attribute to set it at top and left of the EditText view : android:gravity="top|left"
This should do it
txt.setSingleLine(false); txt.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
You may also use this:
txt.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With