I am using rippleeffect library
for my project. But in Android Nougat and Marshmallow
, App crashes due to this library:
compile 'com.github.traex.rippleeffect:library:1.3'
The error message is:
FATAL EXCEPTION: main Process: com.test.testapp, PID: 17713 java.lang.IllegalStateException: Underflow in restore - more restores than saves at android.graphics.Canvas.native_restore(Native Method) at android.graphics.Canvas.restore(Canvas.java:522) at com.andexert.library.RippleView.draw(RippleView.java:170) ........................ ........................
As far as the below link this is a known issue. https://github.com/traex/RippleEffect/issues/76 and I also tried so many solutions from stackoverflow but luck did favor so far!!!
What can be done to solve this problem?
I faced the same issue and did not found a good solution for that.But If you
targetSdkVersion
to 22 you can run it: meaning it does not crash! but I really don't recommend that.'com.github.emanzanoaxa:RippleEffect:52ea2a0ab6'
canvas.save();
before everyrestore()
is another suggestion from your link given that you can tryhttps://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 newRippleDrawable
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:
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
Example 2: Ripple with mask and background color
Example 3: Ripple on top a drawable resource
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