Elevation on AppBarLayout doesn't work

前端 未结 2 2030
盖世英雄少女心
盖世英雄少女心 2021-01-05 03:58

When I try to set a specific value to elevation for AppBarLayout, the shadow disappears completely.

 

        
相关标签:
2条回答
  • 2021-01-05 04:05

    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));
    
    0 讨论(0)
  • 2021-01-05 04:24

    Work for me:

        ViewCompat.setElevation(appBarLayout, getResources().getDimension(R.dimen.toolbar_elevation));
    
    0 讨论(0)
提交回复
热议问题