单击时,波纹效果的一部分不会在图像按钮上消失

时间:2018-06-26 19:05:57

标签: android android-imagebutton

我有一个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时,会出现类似波纹的效果,但是当我抬起手指时,它的一部分不会消失。

我还要附加图片:

When I press ImageButton

after I lift my finger up

1 个答案:

答案 0 :(得分: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"
         />