ToolBar disappears when setting elevation for AppBarLayout

↘锁芯ラ 提交于 2019-12-06 17:35:28

New Update: In Appcompat v24.0.0, you can not set elevation to AppBarLayout using setElevation() and app:elevation as these are deprecated.

You have to use stateListAnimator property to set elevation now.

Note: set duration to 1ms in StateListAnimator in order to avoid delay in Elevation Drawing.

AppBarLayout elevation change is delayed on appCompat v24.0.0

Answer from @Zeeshan is totally right.

as an extra here is a sample code that works

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            StateListAnimator stateListAnimator = new StateListAnimator();
            stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(appBarLayout, "elevation", 0.1f));
            appBarLayout.setStateListAnimator(stateListAnimator);
}

I had to set elevation to 0.1 because setting it to 0 wasn't working, the whole Layout was disappearing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!