I want to create a ripple dynamically in code.
Code:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
buyButton.setBackground(getPressedColorRippleDrawable(primaryColor, darkerVariant));
}
public static RippleDrawable getPressedColorRippleDrawable(int color, int darkerVariant) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ColorStateList colorStateList = new ColorStateList(
new int[][]
{new int[]{}},
new int[]
{darkerVariant}
);
return new RippleDrawable(colorStateList, new ColorDrawable(color), null);
}
return null;
}
This works on Lollipop but makes the app crash on my GNEX (4.3).
Error:
Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method fragments.ProductDetailFragment.getPressedColorRippleDrawable
07-17 12:57:45.757 30992-30992/com.comizzo.ginsonline E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.VerifyError: fragments/ProductDetailFragment
But RippleDrawable is never used on Gnex because code isn't executed.
How can I fix this ?
That code is indeed not being executed. The app crashes because you're receiving a java.lang.VerifyError
. Try performing a Project → Clean
if you're using Eclipse or Build → Rebuild project
if you're using Android Studio.
The issue is that you need to return a Drawable instead of a RippleDrawable in getPressedColorRippleDrawable
. Otherwise, on pre-lollipop devices, you will get a VerifyError.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With