我想动态地在代码中创建一个涟漪。
代码:
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.draable.RippleDrawable’,引用于方法fragments.ProductDetailFragment.getPressedColorRippleDrawable 07-17 12:57:45.757 30992-30992/com.comizzo.ginsonline E/AndroidRuntime:致命例外: main java.lang.VerifyError:片段/产品碎片
但是RippleDrawable从来没有在Gnex上使用,因为代码没有被执行。
我怎么才能解决这个问题?
发布于 2016-03-10 05:11:14
问题是,您需要在getPressedColorRippleDrawable中返回一个可绘制的而不是一个getPressedColorRippleDrawable。否则,在前棒棒糖设备上,您将得到一个VerifyError。
发布于 2015-07-17 13:01:42
这段代码确实没有被执行。这个应用程序崩溃是因为你收到了一个java.lang.VerifyError。如果使用EclipseandBuild → Rebuild project,如果使用Android,请尝试执行Build → Rebuild project。
https://stackoverflow.com/questions/31474297
复制相似问题