Search code examples
androidmaterial-componentsmaterial-components-android

Elevation for Floating action button is not working


I'm using the material components FloatingActionButton https://material.io/develop/android/components/floating-action-button/

In that, I can't able to add elevation for my fab I tried using the below code but it's not working app:elevation="12dp" app:borderWidth="0dp"

Here is my xml.

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/mfab"
        style="@style/Widget.MaterialComponents.FloatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/mainlay"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="-28dp"
        app:elevation="12dp"
        app:borderWidth="0dp"
        app:fabSize="normal"
        app:srcCompat="@drawable/ic_directions_walk_white_18dp" />

Solution

  • AFAIK fab overrides elevation value. So there are two possible solutions: 1. You get source code of fab and change value of elevation 2. You create your own implementation. I'd suggest you to use first solution.