Search code examples
androidandroid-layouttextmultilineandroid-textinputedittext

Setting android:lines on TextInputEditText not working


Do anyone know how to show Total Lines prior display when using TextInputEditText and TextInputLayout? I don't have this problem when using the normal EditText without the TextInputLayout. This is my sample code :

<android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/spacing_small"
                app:counterEnabled="true"
                app:counterMaxLength="1000"
                app:counterOverflowTextAppearance="@style/TextLimitError"
                app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout"
                app:theme="@style/TextInputLayoutStyle">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/input"
                    style="@style/TextInputEditTextStyle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="hint text"
                    android:inputType="textMultiLine"
                    android:lines="5"
                    android:maxLength="1000"/>
</android.support.design.widget.TextInputLayout>

My goal is to have the same effect like html textarea when we're setting the rows attribute.

enter image description here

This is what i got when setting the android:lines on the TextInputEditText. It leave a blank empty space between the floating label and the first letter that i typed.

enter image description here


Solution

  • try android:gravity="top|left" below this may help

    <android.support.design.widget.TextInputLayout
              android:id="@+id/input_layout"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="@dimen/spacing_small"
              app:counterEnabled="true"
              app:counterMaxLength="1000"
              app:counterOverflowTextAppearance="@style/TextLimitError"
              app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout"
              app:theme="@style/TextInputLayoutStyle">
    
                            <EditText
                                android:id="@+id/input"
                                style="@style/TextInputEditTextStyle"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="top|left"
                                android:hint="hint text"
                                android:inputType="textMultiLine"
                                android:lines="3"
                                android:maxLines="5"
                                android:minLines="3"
                                android:maxLength="1000"
                                android:singleLine="false"
                                android:scrollbars="vertical"/>
     </android.support.design.widget.TextInputLayout>