Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultiLine EditText in Android Material design

<android.support.design.widget.TextInputLayout
            android:id="@+id/float_edit_description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/ll4"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/edit_description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:focusable="true"
                android:gravity="top|left"
                android:hint="Description"
                android:inputType="text"
                android:maxLines="3"
                android:paddingTop="0dp"
                android:scrollbars="vertical"
                android:textColor="@android:color/black"
                android:textColorHint="@color/hint_grey" />
        </android.support.design.widget.TextInputLayout>

I want to make the above EditText to have multi line. If the user press "enter" the cursor should get down to the second line.

like image 763
Amardeepvijay Avatar asked Aug 06 '15 09:08

Amardeepvijay


People also ask

How do I allow multiline input using EditText?

You can make your EditTexts multi-line by added certain attributes to the EditTexts View. Also remember to set android:layout_height:wrap_content.

How to display MultiLine text in android?

in this way we can create a multiline TextView widget in android app. we can assign android:text attribute value by this way android:text="Line1 \n Line2 \n Line3" for a TextView widget. this value will display the specified TextView widget's text on three lines.

How to write MultiLine text in android studio?

The maxLines attribute is used to set the maximum line a TextView widget can have. You can prevent the TextView from creating multiple lines by setting the maxLines value as 1 .


2 Answers

Add your EditText

<EditText 
...
android:inputType="textMultiLine"
/>
like image 189
sasikumar Avatar answered Oct 06 '22 11:10

sasikumar


you have to set

default lines in preview by android:lines="5"

limits of lines by android:maxLines="10"

start of typing by android:gravity="start"

try this code:

<EditText
                android:id="@+id/et_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:background="@drawable/ic_launcher"
                android:gravity="start"
                android:hint="hint"
                android:inputType="text"
                android:lines="5"
                android:maxLines="10"
                android:padding="10dp"
                android:textColor="#000" />
like image 23
Ajay Mistry Avatar answered Oct 06 '22 09:10

Ajay Mistry