删除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中的同名资源。

相关推荐
alexhilton4 天前
MVI 让屏幕一次只有一个状态
android·kotlin·android jetpack
Easyhood9 天前
Android 开发入门实践(十四):Compose 副作用入门与四个常用 API
android·开发语言·kotlin·android jetpack·compose
传奇开心果编程11 天前
【Jetpack Compose娓娓道来】第36课:焦点管理与键盘输入——让遥控器、键盘和输入法都“找得到北”
android·kotlin·移动开发·交互·android jetpack·ui框架·声明式ui
巫山老妖12 天前
Android 应用架构演进:MVC / MVP / MVVM / MVI (2026)
android·android jetpack
alexhilton12 天前
2027 Android 开发者路线图:学习、面试与 AI
android·kotlin·android jetpack
灿飞屋13 天前
Kotlin与Java虚拟机四:函数
java·python·kotlin·安卓·android jetpack
alexhilton18 天前
提升 Android Compose 页面的流畅度
android·kotlin·android jetpack
MiyamuraMiyako19 天前
Compose LazyRow 实现尾项露出与少量数据均分
android·android jetpack
传奇开心果编程19 天前
【Jetpack Compose娓娓道来】第29课:状态容器与UI事件建模——把“散装状态”变成“可穷举的契约”
android·kotlin·移动开发·android jetpack·ui框架·开发范式·声明式ui