0

我正在使用 android 中的 FAB,并且我增加了 Src 图像大小以覆盖 FAB,但是现在每当我单击 FAB 时,波纹效果都会显示在图像后面而不是其上方,这不会让人感觉 FAB 被单击

在此处输入图像描述

我的 FAB 代码

    <com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:maxImageSize="@dimen/_130sdp"
    android:layout_gravity="center|bottom"
    android:contentDescription="@string/app_name"
    app:srcCompat="@drawable/ic_radial_gradient"
    app:backgroundTint="@color/white"
    app:elevation="0dp"
    app:layout_anchor="@id/bottomAppBar"
    app:tint="@null"/>
4

2 回答 2

1

您可以简单地使用foregroundfor yourView来实现可点击的效果:应该是这样的:

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:maxImageSize="@dimen/_130sdp"
    android:layout_gravity="center|bottom"
    android:contentDescription="@string/app_name"
    app:srcCompat="@drawable/ic_radial_gradient"
    app:backgroundTint="@color/white"
    app:elevation="0dp"
    app:layout_anchor="@id/bottomAppBar"
    app:tint="@null"
    android:foreground="?android:attr/selectableItemBackgroundBorderless"
/>

我们只需要将这一行添加到View单击时显示涟漪效果。

android:foreground="?android:attr/selectableItemBackgroundBorderless"

于 2021-11-03T09:22:38.967 回答
1

尝试将此行添加到您的 XML

android:foreground="?android:attr/selectableItemBackgroundBorderless"
于 2021-11-03T09:35:26.793 回答