How to allow multi-line in Android's EditText
view?
15 Answers
By default all the EditText
widgets in Android are multi-lined.
Here is some sample code:
<EditText
android:inputType="textMultiLine" <!-- Multiline input -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
android:gravity="top|start" <!-- Cursor Position -->
android:maxLines="10" <!-- Maximum Lines -->
android:layout_height="wrap_content" <!-- Height determined by content -->
android:layout_width="match_parent" <!-- Fill entire width -->
android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>

- 1,613
- 1
- 18
- 39

- 27,760
- 6
- 37
- 35
-
6Is there a way to have inputType set to textMultiLine and imeOptions to actionSend? I see an Enter key on the S4 keyboard instead of send when I set inputType to textMultiLine and imeOptions to actionSend. – user484691 Nov 05 '13 at 05:22
-
1For "textMultiLine and imeOptions" see http://stackoverflow.com/questions/5014219/multiline-edittext-with-done-softinput-action-label-on-2-3 – TOMKA May 18 '15 at 08:10
-
4One thing to note, adding an `inputType` negates at least the `lines` and `minLines` attributes. I had `inputType="phone"` and the lines attributes had no effect – ono Jul 09 '15 at 19:06
-
2Do not use this. Causes an `IndexOutOfBoundsException` as soon as you type something because of `android:inputType="textMultiLine"` – Chisko May 29 '18 at 23:10
-
if using AppCompactTextView need this line android:inputType="textMultiLine" – sourav pandit Mar 17 '20 at 11:33
-
Programmatically: ```txt.setSingleLine(false); txt.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);``` – Hawklike Apr 03 '20 at 13:42
You may find it better to use:
<EditText
...
android:inputType="textMultiLine"
/>
This is because android:singleLine
is deprecated.
-
Sharduls answer should certainly work on modern Apis. Since they removed the deprecated `singleLine` part of their answer (a long time ago). Regarding the question itself, that is the most important part of their answer. – Knossos Jul 21 '16 at 12:41
-
Do not use this. Causes an `IndexOutOfBoundsException` as soon as you type something. Multiline now is the default. – Chisko May 29 '18 at 23:11
-
@Chisko An XML attribute wouldn't cause an IndexOutOfBoundsException. I can't remember when the default inputType changed (did it even?), but it is probably best to keep this in for backwards compatibility reasons. – Knossos May 30 '18 at 06:37
-
1@Knossos well, as strange as it is for you it is for me. I literally copy-pasted the code and crashed every time with every possible combination of several parameters until I removed that. Go figure. – Chisko May 31 '18 at 05:42
This works for me, actually these 2 attributes are important: inputType and lines. Besides, you may need a scrollbar, the code below shows how to make one:
<EditText
android:id="@+id/addr_edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|left"
android:inputType="textEmailAddress|textMultiLine"
android:lines="20"
android:minLines="5"
android:scrollHorizontally="false"
android:scrollbars="vertical" />

- 1,753
- 5
- 19
- 37

- 4,557
- 3
- 19
- 18
This is how I applied the code snippet below and it's working fine. Hope, this would help somebody.
<EditText
android:id="@+id/EditText02"
android:gravity="top|left"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:lines="5"
android:scrollHorizontally="false"
/>
Cheers! ...Thanks.

- 45
- 6

- 2,037
- 9
- 42
- 54
Try this, add these lines to your edit text view, i'll add mine. make sure you understand it
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText_newprom_description"
android:padding="10dp"
android:lines="5"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:minLines="5"
android:gravity="top|left"
android:scrollbars="vertical"
android:layout_marginBottom="20dp"/>
and on your java class make on click listner to this edit text as follows, i'll add mine, chane names according to yours.
EditText description;
description = (EditText)findViewById(R.id.editText_newprom_description);
description.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
this works fine for me

- 1,159
- 2
- 18
- 45

- 619
- 8
- 13
-
Thanks you! This is how I made an edit text scrollable within a scrollable view. – Esdras Lopez Nov 13 '19 at 02:43
EditText has singleLine property. You can set in the XML or by calling setSingleLine(false); http://developer.android.com/reference/android/widget/TextView.html#setSingleLine%28%29

- 2,355
- 2
- 23
- 38
android:inputType="textMultiLine"
This code line work for me. Add this code you edittext in your xml file.

- 757
- 10
- 24
if some one is using AppCompatEditText then you need to set inputType="textMultiLine" here is the code you can copy
<androidx.appcompat.widget.AppCompatEditText
android:padding="@dimen/_8sdp"
android:id="@+id/etNote"
android:minLines="6"
android:singleLine="false"
android:lines="8"
android:scrollbars="vertical"
android:background="@drawable/rounded_border"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_25sdp"
android:layout_marginTop="32dp"
android:layout_marginEnd="@dimen/_25sdp"
android:autofillHints=""
android:gravity="start|top"
android:inputType="textMultiLine"
/>
for background
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/_5sdp"/>
<stroke android:width="1dp" android:color="#C8C8C8"/>
</shape>

- 8,647
- 2
- 19
- 17
All of these are nice but will not work in case you have your edittext inside upper level scroll view :) Perhaps most common example is "Settings" view that has so many items that the they go beyond of visible area. In this case you put them all into scroll view to make settings scrollable. In case that you need multiline scrollable edit text in your settings, its scroll will not work.

- 5,991
- 2
- 29
- 33
To disable number of lines that was previously assigned in theme use xml attribute: android:lines="@null"

- 196
- 2
- 4
<EditText
android:id="@id/editText" //id of editText
android:gravity="start" // Where to start Typing
android:inputType="textMultiLine" // multiline
android:imeOptions="actionDone" // Keyboard done button
android:minLines="5" // Min Line of editText
android:hint="@string/Enter Data" // Hint in editText
android:layout_width="match_parent" //width editText
android:layout_height="wrap_content" //height editText
/>

- 551
- 6
- 16
I learned this from http://www.pcsalt.com/android/edittext-with-single-line-line-wrapping-and-done-action-in-android/, though I don't like the website myself. If you want multiline BUT want to retain the enter button as a post button, set the listview's "horizontally scrolling" to false.
android:scrollHorizontally="false"
If it doesn't work in xml, doing it programmatically weirdly works.
listView.setHorizontallyScrolling(false);

- 2,213
- 4
- 32
- 56

- 612
- 5
- 19
Another neat thing to do is to use android:minHeight
along with android:layout_height="wrap_content"
. This way you can set the size of the edit when it's empty, and when the user inputs stuff, it stretches according to how much the user inputs, including multiple lines.

- 1,404
- 23
- 30
<EditText
android:hint="Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine|textNoSuggestions"
android:id="@+id/edittxtAddress"
android:layout_marginLeft="@dimen/textsize2"
android:textColor="@android:color/white"
android:scrollbars="vertical"
android:minLines="2"
android:textStyle="normal" />
and in Activity to remove "\n" is user press nextline
String editStr= edittxtAddress.getText().toString().trim();
MyString= editStr.replaceAll("\n"," ");

- 881
- 8
- 19