删除AppBarLayout自带阴影

把AppBarLayout的background设置成透明之后,边缘会有阴影效果。elavation设置为0后还是有阴影。

xml 复制代码
<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中的同名资源。

相关推荐
ljt272496066112 小时前
Compose笔记(七十四)--BlurMaskFilter
笔记·android jetpack
ljt272496066114 小时前
Compose笔记(七十五)--withFrameNanos
笔记·android jetpack
hnlgzb1 天前
请详细解释一下MVVM这个设计模型
android·kotlin·android jetpack·compose
hnlgzb3 天前
目前编写安卓app的话有哪几种设计模式?
android·设计模式·kotlin·android jetpack·compose
png4 天前
从零开始Compose天气预报(完结)
android jetpack
阿巴斯甜4 天前
produceState的使用:
android jetpack
阿巴斯甜4 天前
snapshotFlow的使用
android jetpack
菜鸟国国5 天前
从0开始学Jetpack Compose|第二篇:基础组件+核心布局,从零搭建实用UI
android jetpack
simplepeng5 天前
mutableStateOf(list) vs mutableStateListOf():该如何选择?
android jetpack
zh_xuan5 天前
Android Jetpack DataStore存储数据
android·android jetpack·datastore