When upgrading from the Android Support Library v23.4.0 to v24.0.0, setting the elevation to 0 programmatically to an AppBarLayout stopped working:
appBayLayout.setElevation(0);
It does work when setting the elevation in the XML.
When upgrading from the Android Support Library v23.4.0 to v24.0.0, setting the elevation to 0 programmatically to an AppBarLayout stopped working:
appBayLayout.setElevation(0);
It does work when setting the elevation in the XML.
One more possible solution for this is to add
android:stateListAnimator="@null"
to yourAppBarLayout
as shown below.Edit
The
AppBarLayout
from v24.0.0 uses aStateListAnimator
that defines the elevation depending on its state. So usingsetElevation
will have no effect if aStateListAnimator
is being used (which happens by default). Set theelevation
via the XML or programmatically (both for API >= 21):Old answer
This seems to be an issue of the design support library. The problem is related to the way the elevation is set programmatically, using
setElevation
. Setting it from the XML is placing aStateListAnimator
in the view and not callingsetElevation
. However,setElevation
should work.Here there is a workaround:
This is taken from what the constructor does, calling a method in the class
ViewUtilsLollipop
in v24.0.0.