androidmaterial-designtextinputlayout

How to remove shadow from OutlinedBox TextinputLayput's floating label


enter image description here

You can see the background of floating label is not clear(White) it's having some shadow.I tried many things but it did not work.

  <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="12dp"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="8dp"
        android:layout_gravity="center"
        app:hintTextColor="@android:color/black"
        app:boxBackgroundColor="@android:color/white"
        app:boxStrokeColor="@color/text_input_box_stroke"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_margin="8dp"
        app:layout_constraintTop_toTopOf="parent"
        android:hint="Filled box(default)">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            tools:text="@tools:sample/cities"
            android:layout_height="wrap_content" />

    </com.google.android.material.textfield.TextInputLayout>

Strock color

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#0D000000" android:state_focused="true"/>
    <item android:color="#0D000000" android:state_hovered="true"/>
    <item android:color="#0D000000"/>
</selector>

Solution

  • Try this:

    <com.google.android.material.textfield.TextInputLayout
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="username"
                    app:boxCornerRadiusBottomStart="5dp"
                    app:boxCornerRadiusBottomEnd="5dp"
                    app:boxCornerRadiusTopStart="5dp"
                    app:boxCornerRadiusTopEnd="5dp"
                    app:boxStrokeColor="@color/edittext_box_stroke_color"
                    app:errorTextColor="#F81616"
                    app:hintTextColor="#0AB939"
                    app:endIconMode="clear_text"
                    app:endIconTint="#A9A9A9"
                    android:textColorHint="#FFcfcfcf"
                    android:layout_marginTop="10dp"
                    android:layout_marginStart="24dp"
                    android:layout_marginEnd="24dp"
                    android:layout_marginBottom="10dp">
                    <com.google.android.material.textfield.TextInputEditText
                        android:drawableStart="@drawable/user_20"
                        android:drawableTint="@color/edittext_icon_color"
                        android:drawablePadding="8dp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@={viewModel.userName}"
                        android:imeOptions="actionNext"
                        android:inputType="text"
                        android:textColor="#3d3d3d"/>
    
                </com.google.android.material.textfield.TextInputLayout>
    

    Here is edittext_box_stroke_color.xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_focused="true" android:color="#cfcfcf"/>
        <item android:state_focused="false" android:color="#fafafa"/>
    </selector>