Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Ripple effect outside ImageButton

I am trying to implement ripple effect for ImageButton.I have set ripple in background and drawable image in the src for it.

android:background="@drawable/myripplexml" android:src="@drawable/myimagepath" 

Its giving nice ripple effect inside button Layout. But I want Ripple effect to extend outside the Button Layout also.Another way to do it is using :

 android:background="?android:attr/selectableItemBackgroundBorderless" 

But it uses default color and style. How can I customize it regarding color, shape and it's size ?

like image 921
Chaitanya Pimparkar Avatar asked Dec 10 '14 05:12

Chaitanya Pimparkar


2 Answers

I ran into this and my issue is that 'selectableItemBackgroundBorderless' creates a rectangle, while my button was circular. I'm not sure if this answers the original question but here is what I found: set the background to this in drawable-v21

<ripple         xmlns:android="http://schemas.android.com/apk/res/android"         android:color="?android:colorControlHighlight">     <item android:id="@android:id/mask">         <shape android:shape="oval">             <solid android:color="?android:colorAccent" />         </shape>     </item> </ripple> 

and @null in lower api levels (assuming you're using a selector for the actual image button src). The ripple most visible in the padding of the button. If there's no masking layer at all The ripple is unbound and kind of takes over the whole screen. You can use whatever shape you want if not a circle.

like image 135
Travis Castillo Avatar answered Sep 27 '22 21:09

Travis Castillo


If you are lazy like me, make use of the default ripple and forget about backward compatibility. Basically there are two types of background ripple u can add to ur views:

 ?android:selectableItemBackground // Ripple within view  ?android:selectableItemBackgroundBorderless //Ripple outside view 

Unfortunately,these ripples are always grey in color. To tweak these based on your theme, go to ur parent theme and change the colorControlHighlight.

In your app's main theme:

<item name="colorControlHighlight">#1bff3a</item> 

This value will change the colour of the default ripple.

Note: On devices below 21, the ripple will turn into notmal selectors with the same color you have set.

like image 20
amalBit Avatar answered Sep 27 '22 22:09

amalBit