Android imagebutton ripple effect

rub*_*bmz 3 android rippledrawable android-5.0-lollipop

Okay, so I understood ripple effect is only available LOLLIPOP and up. But, still, when setting up my ImageButton, I fail to get a nice ripple effect that would work like a "regular" Button, just show an image instead (and transparent bg)...

I added AppCompat v7 and put the second layout in my drawable/layout-v21 folder, which has the following button in it:

<ImageButton
    android:id="@+id/forward"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="15dp"
    android:scaleType="fitCenter"
    android:height="15dp"
    android:padding="25dp"
    style="@style/Widget.AppCompat.ImageButton"
    android:src="@drawable/forwardplay" />
Run Code Online (Sandbox Code Playgroud)

But the background is grey and the ripple (grey too) cannot be customised.

因此,如果我只有一个不错的涟漪可绘制对象放入我的drawable-v21中,那将会很棒,我可以从ImageButton的background属性中引用它。问题是我找不到原始的Android Ripple效果(我有Samsung S6手机,这是Samsung的主题吗?)

如果有人可以分享他们的绘画作品,我会很乐意。

谢谢!

小智 6

试试这个,绝对可以用:

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@android:drawable/YOUR_BUTTON_SOURCE"
    android:background="?attr/selectableItemBackgroundBorderless"
/>
Run Code Online (Sandbox Code Playgroud)

  • `android:foreground=` 仅适用于 API 23+。如果您使用背景为透明,只需使用 android:background="?attr/selectableItemBackgroundBorderless"` 它将使背景透明并提供漂亮的波纹效果。 (2认同)

Vis*_*kar 0

尝试使用

android:background="?selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)