how to create ripple effect for pre-lollipop
For lollipop(API>21) make file as btn_ripple_effect.xml in drawable-v21 and put below code
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="?android:colorAccent"
tools:targetApi="lollipop">
<item android:drawable="@color/cancel_btn_clr" /> <!-- default -->
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
For pre lollipop (API<21)make file as btn_ripple_effect.xml in drawable folder and put below code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="@color/colorAccent"></solid>
</shape>
</item>
<item>
<shape>
<solid android:color="@color/cancel_btn_clr"></solid>
</shape>
</item>
</selector>
Create button as below
<Button
android:id="@+id/button3"
style="@style/cancel_btn_style"
android:layout_marginLeft="50dp"
android:text="Cancel"
/>
Add this in your style.xml
<style name="cancel_btn_style" parent="Theme.AppCompat">
<item name="android:textSize">15sp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:layout_height">36dp</item>
<item name="android:layout_width">90dp</item>
<item name="android:background">@drawable/btn_ripple_effect</item>
You could try this library balysv/material-ripple.
In your gradle, add this line :
compile 'com.balysv:material-ripple:1.0.2'
And this is how to do it :
<com.balysv.materialripple.MaterialRippleLayout
android:id="@+id/ripple"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Button inside a ripple"/>
</com.balysv.materialripple.MaterialRippleLayout>
For lollipop(API>21) make file as btn_ripple_effect.xml in drawable-v21 and put below code
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#f8c7c9c8"
tools:targetApi="lollipop">
<item android:id="@android:id/mask">
<shape android:shape="oval">
<corners android:radius="@dimen/dp10" />
<solid android:color="#f8ced6d2" />
</shape>
</item>
</ripple>
For pre lollipop (API<21)make file as btn_ripple_effect.xml in drawable folder and put below code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="#f8ced6d2"/>
</shape>
</item>
<item>
<shape>
<solid android:color="@color/transparent"/>
</shape>
</item>
</selector>
use it on imageview like this
<ImageView
android:id="@+id/imageViewOffer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="@drawable/btn_ripple_effect"
android:src="@mipmap/ic_offers"/>
I know this is old but you can perform your action in onRippleCompleteListener provided by the library. Something like :
rippleView.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
@Override
public void onComplete(RippleView rippleView) {
//Your code here...
}
});
Hope this helps. :)