本文介绍了不能转换为LayerDrawable了(V7升级后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是支持库的最后一个版本,22.1.1。
I'm using last version of the support libraries, 22.1.1.
我去,如:
mRatingBar = (RatingBar) getActivity().findViewById(R.id.rating);
LayerDrawable layer = (LayerDrawable) mRatingBar.getProgressDrawable();
但升级后崩溃在与2号线一 ClassCastException异常
:
android.support.v4.graphics.drawable.DrawableWrapperHoneycomb cannot be cast to android.graphics.drawable.LayerDrawable
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:725)
我测试在Android 4.2.2。任何提示和放大器;解决方法吗?
I'm testing on Android 4.2.2. Any hints & workaround?
推荐答案
我发现 getProgressDrawable()
不返回我的 LayerDrawable
了。
我是通过设定一个风格 LayerDrawable
的背景下,有:
I was setting a LayerDrawable
background through style, with:
<item name="android:ratingBarStyle">@style/myRatingBarStyle</item>
由于v21.1加入的RatingBar
, AppCompatRatingBar
,他们现在读属性的色彩感知版本从 ratingBarStyle
,而不是的android:ratingBarStyle
。所以我不得不更换上述行:
Since v21.1 added a tint-aware version of the RatingBar
, AppCompatRatingBar
, they are now reading attributes from ratingBarStyle
, rather than android:ratingBarStyle
. So I had to replace the above line with:
<item name="ratingBarStyle">@style/myRatingBarStyle</item>
<item name="android:ratingBarStyle">@style/myRatingBarStyle</item> //API21+
这篇关于不能转换为LayerDrawable了(V7升级后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!