Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 776
2MuchSmoke Avatar asked Dec 07 '22 15:12

2MuchSmoke


2 Answers

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>
like image 103
Omkar Avatar answered Dec 11 '22 10:12

Omkar


set android:gravity="top|left" is working ,like below:

 <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <android.support.design.widget.TextInputEditText
                android:id="@+id/notesValue"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="left|top"
                android:hint="@string/mlNote"
                android:inputType="textCapSentences|textMultiLine"
                android:lines="3" />
        </android.support.design.widget.TextInputLayout>
like image 39
zhangjin Avatar answered Dec 11 '22 09:12

zhangjin