Search code examples
androidandroid-textinputlayout

The visibility of TextInputLayout with OutlineBox style can't be set to GONE properly


I have three TextInputLayouts with OutlineBox style in a ConstraintLayout as below. In the activity onCreate I need to don't show the last one so I set its visibility to GONE with this piece of code (I'm using Kotlin): etCompanyName.visibility = View.GONE. But a narrow line still remains in the layout as you see in the picture. What can I do to disappear the TextInputLayout properly?

<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


Solution

  • Try setting the visibility: gone property to text input layout element instead of editText.

    tilCompanyName.visibility = View.GONE