找不到RippleDrawable。

10

我希望在代码中动态地创建涟漪。

代码:

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,因为代码没有执行。

我该如何解决这个问题?

2个回答

8
问题在于你需要返回一个Drawable而不是RippleDrawable,否则在低于5.0版本的设备上会出现VerifyError错误。请在getPressedColorRippleDrawable中进行修改。

4

那段代码确实没有执行。应用程序崩溃是因为你收到了一个java.lang.VerifyError。如果你使用的是Eclipse,请尝试执行Project → Clean,如果你使用的是Android Studio,请尝试执行Build → Rebuild project


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接