How to make multi-line edittext in android

I am trying to create a dynamic speaker using LayoutParams.MATCHPARENT for its width and height. I tried the following code but it still does not work.

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 allows me to enter several lines, and the 'ENTER' button is displayed on the keyboard, but as you enter text in the editor, the edit text scrolls horizontally if the text is not wide enough to display the text. Can someone please help me how to make edittext multi-line?

+8
android android-edittext multiline
source share
4 answers

Try the following code

 editor.setSingleLine(false); editor.setHorizontalScrollBarEnabled(false); 
+8
source share

Try this code

  txt.setSingleLine(false); txt.setLines(14); txt.setMinLines(13); txt.setMaxLines(15); txt.setGravity(Gravity.LEFT | Gravity.TOP); 
+5
source share

Try

 android:scrollHorizontally="false" 

for edittext

+1
source share

Add the line below to your code, this may help you.

 editor.setSingleLine(false); 
+1
source share

All Articles