找不到RippleDrawable [英] Could not find RippleDrawable

查看:131
本文介绍了找不到RippleDrawable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在代码中动态创建涟漪图.

I want to create a ripple dynamically in code.

代码:

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)上崩溃.
错误:

This works on Lollipop but makes the app crash on my GNEX (4.3).
Error:

找不到方法片段中引用的类'android.graphics.drawable.RippleDrawable'.ProductDetailFragment.getPressedColorRippleDrawable

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:致命异常:主要

07-17 12:57:45.757 30992-30992/com.comizzo.ginsonline E/AndroidRuntime﹕ FATAL EXCEPTION: main

java.lang.VerifyError:片段/ProductDetailFragment

java.lang.VerifyError: fragments/ProductDetailFragment

但是RippleDrawable从未在Gnex上使用,因为未执行代码.

But RippleDrawable is never used on Gnex because code isn't executed.

我该如何解决?

推荐答案

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

The issue is that you need to return a Drawable instead of a RippleDrawable in getPressedColorRippleDrawable. Otherwise, on pre-lollipop devices, you will get a VerifyError.

这篇关于找不到RippleDrawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆