0

I try to add elevation to my TextInputLayout but android:elevation="10dp doesn't work! How can I do this?

  <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:elevation="10dp>

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:focusableInTouchMode="true"
            />

    </com.google.android.material.textfield.TextInputLayout>
2
  • 2
    By default, Views won't cast a shadow unless they have a non-null background set, and TextInputLayout doesn't have one. It manages the background on the nested EditText instead. You could simply set your own background on it, but that might taking some fiddling to get it to line up correctly with the other decorations. Also, it's not clear how you want this to look, exactly, but I should mention that the shadow will not be affected by TextInputLayout's cutout, and the floating hint has no background of its own, so you might end up with some ugly artifacts in certain styles/themes. Commented Jan 7, 2023 at 17:46
  • 1
    I just realized that for the basic style, you might be able to get away with only setting android:outlineProvider="bounds" on the <TextInputLayout>. That'll cause the shadow to be strictly rectangular, but with a small corner radius it's not really noticeable: i.sstatic.net/lqizJ.png. Commented Jan 8, 2023 at 2:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.