【问题标题】:Multiline does not work inside TextInputLayout多行在 TextInputLayout 中不起作用
【发布时间】:2019-11-21 01:36:19
【问题描述】:

无论我做什么,我都无法将我的EditText 多列在TextInputLayout 中(必须添加InputLayout 用于字符计数器)。 因此,当我输入某些内容时,它会水平移动,而不是一段时间后进入新行。 如您所知,在正常的EditTexts 中,多行可以解决问题,但在这种情况下不会。你怎么看?谢谢。

   <?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>

【问题讨论】:

    标签: android android-edittext multiline textinputlayout


    【解决方案1】:

    这也有效:

    android:inputType="textPersonName | textMultiLine"
    
    

    【讨论】:

    • 这应该记录在材料文本字段页面上。这正是我想要的!
    【解决方案2】:

    我做到了。您必须为相关的 EditText 添加“以编程方式”edittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);

    在我的例子中,有趣的是当你将多行代码添加到 xml 时,多行不起作用(使用 TextInputLayout)但它以这种方式工作。希望对我们中的一些人有所帮助。

    【讨论】:

    • 拯救了我的一天!很遗憾 xml 选项不起作用,当它是他们的工作时......
    • 很高兴听到它帮助了你的朋友。仍然是一个谜,为什么它只能以这种方式工作
    • 截至今天,如果在 XML 布局中定义,它现在应该可以工作了。 android:inputType="text|textMultiLine"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    • 2021-03-07
    • 2020-12-17
    相关资源
    最近更新 更多