Could not find RippleDrawable

雨燕双飞 提交于 2019-11-26 11:27:41

问题


I want to create a ripple dynamically in code.

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;
}

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

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

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

How can I fix this ?


回答1:


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.




回答2:


That code is indeed not being executed. The app crashes because you're receiving a java.lang.VerifyError. Try performing a Project → Clean if you're using Eclipse or Build → Rebuild project if you're using Android Studio.



来源:https://stackoverflow.com/questions/31474297/could-not-find-rippledrawable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!