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 ?