Edit
AppBarLayout of v24.0.0 uses the StateListAnimator , which determines the height depending on its state. Therefore, using setElevation will have no effect if StateListAnimator used (which happens by default). Set elevation via XML or programmatically (as for API> = 21):
StateListAnimator stateListAnimator = new StateListAnimator(); stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0)); appBarLayout.setStateListAnimator(stateListAnimator);
Old answer
This seems to be a design support library issue. The problem is how the height is set programmatically using setElevation . An installation from XML puts StateListAnimator in the view and does not call setElevation . However, setElevation should work.
There is a workaround here:
setDefaultAppBarLayoutStateListAnimator(appBarLayout, 0); @SuppressLint("PrivateResource") private static void setDefaultAppBarLayoutStateListAnimator(final View view, final float targetElevation) { final StateListAnimator sla = new StateListAnimator(); // Enabled, collapsible and collapsed == elevated sla.addState(new int[]{android.R.attr.enabled, android.support.design.R.attr.state_collapsible, android.support.design.R.attr.state_collapsed}, ObjectAnimator.ofFloat(view, "elevation", targetElevation)); // Enabled and collapsible, but not collapsed != elevated sla.addState(new int[]{android.R.attr.enabled, android.support.design.R.attr.state_collapsible, -android.support.design.R.attr.state_collapsed}, ObjectAnimator.ofFloat(view, "elevation", 0f)); // Enabled but not collapsible == elevated sla.addState(new int[]{android.R.attr.enabled, -android.support.design.R.attr.state_collapsible}, ObjectAnimator.ofFloat(view, "elevation", targetElevation)); // Default, none elevated state sla.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0)); view.setStateListAnimator(sla); }
This is taken from what the constructor does by calling the method in the ViewUtilsLollipop class in v24.0.0.
bryant1410
source share