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

相关推荐
alexhilton2 天前
Android的Agent优先时代:构建时vs运行时
android·kotlin·android jetpack
我命由我123452 天前
Android 开发问题:View 的 getWidth、getHeight 方法返回的值都为 0
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
QING6183 天前
Kotlin 协程新手指南 —— 结构化并发
android·kotlin·android jetpack
我命由我123453 天前
由 ImageView 获取到的 Drawable 对象,它的 intrinsicWidth、intrinsicWidth 与实际图片的尺寸
java·开发语言·java-ee·android studio·android jetpack·android-studio·android runtime
QING6184 天前
Kotlin 协程新手指南 —— 协程上下文与调度器
android·kotlin·android jetpack
QING6184 天前
Kotlin 协程新手指南 —— 协程基础与挂起函数
android·kotlin·android jetpack
李斯维4 天前
Jetpack 可观察数据容器 LiveData 的高级用法
android·android jetpack·androidx
我命由我123456 天前
Kotlin 开发 - Kotlin 反引号转义关键字
android·java·开发语言·java-ee·kotlin·android jetpack·android runtime
alexhilton9 天前
AppFunctions:让你的Android应用更容易被AI智能体发现
android·kotlin·android jetpack