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

相关推荐
alexhilton1 天前
Compose中的CameraX二维码扫描器
android·kotlin·android jetpack
QING6182 天前
Kotlin之【init】—— 新手须知
android·kotlin·android jetpack
我命由我123453 天前
Android 开发问题:Unresolved reference: kapt
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
阿巴斯甜3 天前
MultiDex的使用:
android jetpack
阿巴斯甜3 天前
Media3 的使用
android jetpack
阿巴斯甜3 天前
CameraX的使用:
android jetpack
阿巴斯甜3 天前
Accompanist的使用:
android jetpack
阿巴斯甜3 天前
Activity Result API 的使用:
android jetpack
阿巴斯甜3 天前
DataStore的使用:
android jetpack
我命由我123455 天前
Android 开发问题:无法从存储库 “D:\keys\MyNotifications.jks“ 中读取密钥 MyNotifications.
android·java·java-ee·android studio·android jetpack·android-studio·android runtime