Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline does not work inside TextInputLayout

Whatever I do, I couldn’t manage to make my EditText multilined inside TextInputLayout (had to add InputLayout for character counter). So when I enter something, it goes horizontally instead of going to a new line after a while. As you know very well, inside normal EditTexts, multiline does the trick but not in this case. What do you think? Thank you.

   <?xml version="1.0" encoding="utf-8"?>


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >


    <android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="4dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="40dp"
        android:layout_weight="1"
        app:layout_constraintBottom_toTopOf="@+id/adViewNewEntry"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.134">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/textContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:padding="28dp"
            app:counterEnabled="true"
            app:counterMaxLength="280"

            app:layout_constraintBottom_toTopOf="@+id/save_button"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:layout_marginBottom="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"

                android:background="@android:color/transparent"
                android:gravity="top|left"

                android:inputType="textNoSuggestions|textMultiLine"
                android:maxLines="10"


                android:scrollbars="vertical"

                />

        </android.support.design.widget.TextInputLayout>
    </android.support.v7.widget.CardView>


    <Button
        android:id="@+id/save_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="15dp"
        android:layout_marginStart="256dp"
        android:layout_marginTop="8dp"
        android:layout_weight="1"
        android:onClick="saveToDatabase"
        android:text="SAVE"
        app:layout_constraintBottom_toTopOf="@+id/adViewNewEntry"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.75"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/cardView"
        app:layout_constraintVertical_bias="0.0" />

        <com.google.android.gms.ads.AdView
            android:id="@+id/adViewNewEntry"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:adSize="BANNER"
            app:adUnitId="ca-app-pub-xxx/xxx"
            app:layout_anchor="@+id/include"
            app:layout_anchorGravity="bottom|center"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"></com.google.android.gms.ads.AdView>


    </android.support.constraint.ConstraintLayout>
like image 855
mears Avatar asked Jul 18 '18 00:07

mears


People also ask

How do I get rid of TextInputLayout padding?

You can remove extra space above AppCompatEditText by setting app:hintEnabled="false" to TextInputLayout but it won't display hint until you re-enable that.

What is the use of TextInputLayout in Android?

Layout which wraps a TextInputEditText , EditText , or descendant to show a floating label when the hint is hidden while the user inputs text.


1 Answers

This works too:

android:inputType="textPersonName | textMultiLine"

like image 94
Jose Avatar answered Nov 04 '22 09:11

Jose