【问题标题】:How to give ripple effect above Src image in FAB如何在 FAB 中的 Src 图像上方产生波纹效果
【发布时间】:2021-12-17 15:51:47
【问题描述】:
我正在使用 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"/>
【问题讨论】:
标签:
java
android
android-studio
floating-action-button
ripple-effect
【解决方案1】:
您可以简单地将foreground 用于您的View 以实现可点击效果:
应该是这样的:
<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"
【解决方案2】:
尝试将此行添加到您的 XML 中
android:foreground="?android:attr/selectableItemBackgroundBorderless"