Search code examples
android-studioandroid-layoutmaterial-designmaterial-components-androidandroid-textinputlayout

How to remove box and add only underline like the old style for android TextInputLayout in android studio


I want to create the following without setting the style to legacy because it creates other problems for example for AutoCompleteTextView.

style="@style/Widget.Design.TextInputLayout"

enter image description here


Solution

  • You can use app:boxBackgroundColor="@android:color/transparent" on FilledBox style TextInputLayout to only have an underline without the box.

    Like this :

     <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/outlinedTextField"
            style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:boxBackgroundColor="@android:color/transparent"
            android:hint="label">
    
            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
    
        </com.google.android.material.textfield.TextInputLayout>
    

    And if you want to remove both box and underline use this : app:boxBackgroundMode="none"