I try to create an edittext dynamically with LayoutParams.MATCHPARENT for its both width and height. I have tried the following code, but it is still not working.
EditText editor = ....;
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1);
editor.setLayoutParams(params);
editor.setGravity(Gravity.LEFT | Gravity.TOP);
editor.setBackgroundColor(Color.WHITE);
editor.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
editor.setTextColor(Color.BLACK);
//editor.setSingleLine(false);
editor.setFocusableInTouchMode(true);
editor.setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE | EditorInfo.TYPE_TEXT_FLAG_IME_MULTI_LINE);
editor.setMaxLines(Integer.MAX_VALUE);
editor.setHorizontallyScrolling(false);
editor.setTransformationMethod(null);
The code above let me to enter several lines, and an 'ENTER' button is displayed in the keyboard, but as I type on the edittext, the edit text scrolls horizontally if the width is not enough to display the text. Can anybody please help me how to make the edittext multiline?
Just add this android:inputType="textMultiLine" in XML file on relevant field.
For this you have to declare a line of code into layout file 'android:text="@string/text"' and go to the \\app\src\main\res\values\strings. xml and add a line of code ' Your multiline text here' Also use '\n' to break the line from any point else the line will automatically be adjusted. Save this answer.
Try this following code
editor.setSingleLine(false);
editor.setHorizontalScrollBarEnabled(false);
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