Android Collapsing Toolbar remove elevation and shadow

You can do this by setting a custom stateListAnimator:

create a new animator "appbar_not_elevated.xml" in animator under res.

<item app:state_collapsible="true" app:state_collapsed="true">
    <objectAnimator android:propertyName="elevation"
                    android:valueTo="0"
                    android:valueType="floatType"
                    android:duration="1"/>
</item>

<item>
    <objectAnimator android:propertyName="elevation"
                    android:valueTo="0"
                    android:valueType="floatType"
                    android:duration="1"/>
</item>

This will set the elevation of collapsed as well as expanded state elevation to zero.

Then set the stateListAnimator to AppBarLayout:

android:stateListAnimator="@animator/appbar_not_elevated"

Just set

android:stateListAnimator="@null"

or

app:elevation="0dp"

NOTE: you should use app: namespace NOT android:

to your AppBarLayout


Depending on the support library used, if you read the source code to set app bar elevation, you'll read:

/**
 * @deprecated target elevation is now deprecated. AppBarLayout's elevation is now
 * controlled via a {@link android.animation.StateListAnimator}. If a target
 * elevation is set, either by this method or the {@code app:elevation} attribute,
 * a new state list animator is created which uses the given {@code elevation} value.
 *
 * @attr ref android.support.design.R.styleable#AppBarLayout_elevation
 */

which tells you, either you use app:elevation or a state list animator. For the second option, add an xml selector into the folder animator-v21, and then set it to something like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <objectAnimator android:duration="1"
                    android:propertyName="elevation"
                    android:valueTo="0dp"
                    android:valueType="floatType"/>
</item>

then refer it from your app bar in xml:

android:stateListAnimator="@animator/my_appbar_state_list_animator"