Android版的RatingBar:getProgressDrawable不强制转换为正确的类 [英] Android RatingBar: getProgressDrawable doesn't cast to right Class
本文介绍了Android版的RatingBar:getProgressDrawable不强制转换为正确的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用
这行code的
LayerDrawable stars = (LayerDrawable) rating_bar.getProgressDrawable();
在我的Nexus 4仿真器API V21工作正常。
当试图在我的Galaxy S4 API V19相同的code,我得到了以下错误消息:
works fine on my Nexus 4 emulator API v21. When trying the same code on my Galaxy S4 API v19, I get the following error message:
Caused by: java.lang.ClassCastException: android.support.v7.internal.widget.TintDrawableWrapper cannot be cast to android.graphics.drawable.LayerDrawable
这是怎么回事?
我与最新版本的工具22楼,我的目标API是22为好。
I am building with the latest build tools 22, my target API is 22 is as well.
推荐答案
在错误信息解释清楚会发生什么:
What happens is clearly explained in the error message :
TintDrawableWrapper cannot be cast to android.graphics.drawable.LayerDrawable
支持LIB为了处理复古兼容性创建一个包装,你只需要考虑到这一点。看一看的lib实施,它可能环绕一个 LayerDrawable
。
您需要做的线沿线的东西:
You will need to do something along the lines of :
LayerDrawable stars = getProgressDrawable(rating_bar);
}
private LayerDrawable getProgressDrawable(RatingBar ratingBar) {
if (Build.VERSION >= LOLLIPOP) {
return (LayerDrawable) ratingBar.getProgressDrawable();
} else {
// fetch the LayerDrawable based on Google's support implementation,
// probably a simple findViewById()
}
}
这篇关于Android版的RatingBar:getProgressDrawable不强制转换为正确的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文