Remove elevation shadow without removing elevation itself

AndroidAndroid ToolbarShadowAndroid AppbarlayoutAndroid Elevation

Android Problem Overview


Is there a way for AppBarLayout to no drop shadow and keep its elevation?

<android.support.design.widget.AppBarLayout
        app:elevation="0dp">

Android Solutions


Solution 1 - Android

To complete M.Sandholtz answer, you can also define this in XML, with outlineProvider="none".

<View
    android:id="@+id/viewElevationNoShadow"
    android:outlineProvider="none"
    android:elevation="4dp"/>

Solution 2 - Android

I just ran into this same problem and this is what fixed it for me:

val withElevationNoShadow = view.findViewById<*your view type*>(*your view id*)
withElevationNoShadow.outlineProvider = null

Keep in mind that the code above is Kotlin, but the Java is almost identical.

This works because shadows are drawn by ViewOutlineProviders. By setting your view's ViewOutlineProvider to null, you take away the default shadow.

For more info about ViewOutlineProviders check out

https://developer.android.com/reference/android/view/ViewOutlineProvider

and

https://developer.android.com/training/material/shadows-clipping

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJocky DoeView Question on Stackoverflow
Solution 1 - AndroidSean BlahoviciView Answer on Stackoverflow
Solution 2 - AndroidClark SandholtzView Answer on Stackoverflow