5

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

Omkar
  • 3,040
  • 1
  • 22
  • 42
2MuchSmoke
  • 103
  • 2
  • 10

2 Answers2

9

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>
Omkar
  • 3,040
  • 1
  • 22
  • 42
  • This also worked for me, but I have to specify `android:lines` and provide a fixed number there. Do you know of a way to make it accept a variable amount of lines, preferably wrapping the text? – Dambakk Apr 02 '20 at 07:46
  • @Dambakk are you talking about providing dynamic number of lines..... if yes then try to set lines programatically. – Omkar Apr 02 '20 at 11:09
  • Yes, that works fine, but what about when the user enters more text? The text should wrap into new lines but it doesnt. Do you know why or how to achieve that behavior? – Dambakk Apr 02 '20 at 11:16
  • Oh, I just had to set `isSingleLine = false`. Embarrassing.. :) – Dambakk Apr 02 '20 at 11:20
  • 1
    ohh lol :) happy to help you and will update my code with your suggestion... – Omkar Apr 02 '20 at 11:21
6

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>
zhangjin
  • 167
  • 2
  • 5