把AppBarLayout的background设置成透明之后,边缘会有阴影效果。elavation设置为0后还是有阴影。
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:elevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="AppBarLayout" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
原因
AppBarLayout的阴影是通过R.dimen.design_appbar_elevation来设置的,并没有通过自定义属性来设置。AppBarLayout的源码注释有一个TODO:This should be a customizable attribute,说明未来是google应该会把这个参数改为自定义的属性。
解决方法
在dimens.xml中添加design_appbar_elevation即可,打包的时候自动替换AppBarLayout中的同名资源。