Elevation on AppBarLayout doesn't work

亡梦爱人 提交于 2019-11-30 22:19:34

Setting Property Animation

Creating an animation with 1ms of execution time:/animator/appbar_elevation.xml

<?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="2dp"
        android:valueType="floatType" />
</item>
</selector>

Setting it to AppBarLayout

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"    
    android:stateListAnimator="@animator/appbar_elevation">
</android.support.design.widget.AppBarLayout>

And it can use in java code.

appBarLayout.setStateListAnimator(AnimatorInflater.loadStateListAnimator(getContext(), R.animator.appbar_elevation));

Work for me:

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