我希望在代码中动态地创建涟漪。
代码:
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;
}
这可以在Lollipop上运行,但会使我的GNEX(4.3)应用程序崩溃。
错误:
未找到类“android.graphics.drawable.RippleDrawable”,该类被引用于方法fragments.ProductDetailFragment.getPressedColorRippleDrawable中
07-17 12:57:45.757 30992-30992 / com.comizzo.ginsonline E / AndroidRuntime:致命异常:主要的
java.lang.VerifyError:片段/ProductDetailFragment
但是在Gnex上从未使用RippleDrawable,因为代码没有执行。
我该如何解决这个问题?