java.lang.IllegalStateException: Underflow in restore - more restores than saves

I faced the same issue and did not found a good solution for that.But If you

  • Downgrade targetSdkVersion to 22 you can run it: meaning it does not crash! but I really don't recommend that.
  • Try to compile it with compile this dependency ->'com.github.emanzanoaxa:RippleEffect:52ea2a0ab6'
  • Call canvas.save(); before every restore() is another suggestion from your link given that you can try
  • You can also try to add that library inside your project and use it

https://codeload.github.com/traex/RippleEffect/zip/master (from the link you provided there are solutions that people have tried use them)


Or i suggest you to create them by yourself no libraries needed at all!

Ripple touch effect was introduced in Android 5.0 (API level 21) and the animation is implemented by the new RippleDrawable class.

General, ripple effect for regular buttons works by default in API 21 and for other touchable views, it can be achieved by specifying:

android:background="?attr/selectItemBackground"

for ripples contained within the view or:

android:background="?attr/selectItemBackgroundBorderless"

for ripples that extend beyond the view's bounds.

You can achieve the same in code using:

int[] attrs = new int[]{R.attr.selectItemBackground};
TypedArray typedArray = getActivity().obtainStyledAttributes(attrs);
int backgroundResource = typedArray.getResourceId(0, 0);
myView.setBackgroundResource(backgroundResource);

If you want to customize the ripple effect into a view, you need to create a new XML file, inside the drawable directory.

Examples:

Example 1: An unbounded ripple

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#ffff0000" />

Example 2: Ripple with mask and background color

<ripple android:color="#7777666"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/mask"
        android:drawable="#ffff00" />
    <item android:drawable="@android:color/white"/>
</ripple>

Example 3: Ripple on top a drawable resource

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#ff0000ff">
    <item android:drawable="@drawable/my_drawable" />
</ripple>

How to Use: To attach your ripple xml file to any view, set it as background as following: assuming your ripple file is named my_ripple.xml. in exmple 1, 2 or 3

<View 
    android:id="@+id/myViewId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/my_ripple" />

they fixed the bug :P RippleEffect