Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply Material Design Touch Ripple to ImageButton?

I have an imagebutton that doesn't respond with a touch animation when it is clicked because it is a static image unlike regular buttons on lollipop which come with the built in ripple effect. I would like to add the material design ripple touch effect to the image but can't seem to find a way to implement it. I can set a color filter over the image but that is not the ripple effect. An example of what I'm trying to do is when you hold an album cover image in Google Play Music and a shadow ripple moves across the image.

like image 279
sanic Avatar asked Jun 20 '15 22:06

sanic


People also ask

What is Android ImageButton?

An ImageButton is an AbsoluteLayout which enables you to specify the exact location of its children. This shows a button with an image (instead of text) that can be pressed or clicked by the user.

What is material button in Android?

Material Button is a customizable button component with updated visual styles. This button component has several built-in styles to support different levels of emphasis, as typically any UI will contain a few different buttons to indicate different actions.


2 Answers

For even better result:

<ImageButton     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:src="@android:drawable/ic_button"     android:background="?attr/selectableItemBackgroundBorderless" /> 
like image 129
i.shadrin Avatar answered Oct 20 '22 14:10

i.shadrin


You can just add a background to your ImageButton like this :

<ImageButton     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:src="@android:drawable/btn_dialog"     android:background="?android:attr/selectableItemBackground" /> 
like image 37
Nicolas Avatar answered Oct 20 '22 13:10

Nicolas