带有OutlineBox样式的TextInputLayout的可见性无法正确设置为GONE

时间:2018-12-12 08:22:24

标签: android android-textinputlayout

我在ConstraintLayout中有三个具有OutlineBox样式的TextInputLayouts,如下所示。在活动onCreate中,我不需要显示最后一个,因此我使用这段代码(我正在使用Kotlin)将其可见性设置为GONEetCompanyName.visibility = View.GONE。但是,如您在图片中看到的,布局中仍然保留了一条细线。我该怎么办才能正确消失TextInputLayout?

<android.support.design.widget.TextInputLayout
        android:id="@+id/tilFirstName"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/etFirstName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_first_name" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/tilLastName"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tilFirstName">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/etLastName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_last_name" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/tilCompanyName"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tilLastName">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/etCompanyName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_company_name" />
    </android.support.design.widget.TextInputLayout>

screenshot of layout

1 个答案:

答案 0 :(得分:0)

尝试将可见性:God属性设置为文本输入布局元素,而不是editText。

tilCompanyName.visibility = View.GONE