【发布时间】:2015-10-07 02:02:03
【问题描述】:
我想在代码中动态创建波纹。
代码:
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: FATAL EXCEPTION: main
java.lang.VerifyError: 片段/ProductDetailFragment
但是 RippleDrawable 从来没有在 Gnex 上使用,因为代码没有被执行。
我该如何解决这个问题?
【问题讨论】: