找不到 RippleDrawable
Could not find RippleDrawable
我想在代码中动态创建波纹。
代码:
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) 上崩溃。
错误:
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
但 RippleDrawable 从未在 Gnex 上使用,因为代码未被执行。
我该如何解决这个问题?
该代码确实没有被执行。该应用程序崩溃,因为您收到 java.lang.VerifyError
。如果您使用的是 Eclipse,请尝试执行 Project → Clean
;如果您使用的是 Android Studio,请尝试执行 Build → Rebuild project
。
问题是您需要 return Drawable 而不是 getPressedColorRippleDrawable
中的 RippleDrawable。否则,在棒棒糖之前的设备上,您将收到 VerifyError。
我想在代码中动态创建波纹。
代码:
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) 上崩溃。
错误:
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
但 RippleDrawable 从未在 Gnex 上使用,因为代码未被执行。
我该如何解决这个问题?
该代码确实没有被执行。该应用程序崩溃,因为您收到 java.lang.VerifyError
。如果您使用的是 Eclipse,请尝试执行 Project → Clean
;如果您使用的是 Android Studio,请尝试执行 Build → Rebuild project
。
问题是您需要 return Drawable 而不是 getPressedColorRippleDrawable
中的 RippleDrawable。否则,在棒棒糖之前的设备上,您将收到 VerifyError。