点击图像按钮时,涟漪效果的一部分没有消失。

3

我有一个ImageButton, 我设置它的背景如下以产生涟漪效果:

  android:background="?attr/selectableItemBackgroundBorderless"

我的ImageButton:

<ImageButton
        android:id="@+id/ibn_option"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_centerHorizontal="true"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:scaleType="fitCenter"
        android:src="@drawable/ic_icon"
        tools:ignore="ContentDescription" />

问题 当我按下这个ImageButton时,会出现类似涟漪的效果,但是当我抬起手指时,其中一部分没有消失。
我还附上了图片:
当我按下ImageButton时:When I press ImageButton 当我抬起手指后:after I lift my finger up

尝试使用前景而不是:android:foreground="?attr/selectableItemBackgroundBorderless" - Skizo-ozᴉʞS ツ
1个回答

0

不要将 selectableItemBackgroundBorderless 作为 android:background,而是将其放在 android:foreground 中,如下所示:

android:foreground="?attr/selectableItemBackgroundBorderless"

这是我的做法:

<ImageButton
        android:id="@+id/ibn_option"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:foreground="?attr/selectableItemBackgroundBorderless"
        android:scaleType="centerCrop"
        android:background="@mipmap/ic_launcher"
         />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接