【问题标题】:Could not find RippleDrawable找不到 RippleDrawable
【发布时间】: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 上使用,因为代码没有被执行。

我该如何解决这个问题?

【问题讨论】:

    标签: android rippledrawable


    【解决方案1】:

    问题是您需要在getPressedColorRippleDrawable 中返回 Drawable 而不是 RippleDrawable。否则,在棒棒糖之前的设备上,您将收到一个 VerifyError。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-27
        • 1970-01-01
        • 2015-08-13
        • 2015-05-17
        相关资源
        最近更新 更多