Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make multiline edittext in android

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?

like image 787
user1553837 Avatar asked Jul 31 '12 12:07

user1553837


People also ask

How to add Multiline EditText in android?

Just add this android:inputType="textMultiLine" in XML file on relevant field.

How to display Multiline text in android?

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.


1 Answers

Try this following code

editor.setSingleLine(false);
editor.setHorizontalScrollBarEnabled(false);
like image 61
koti Avatar answered Sep 27 '22 02:09

koti