Issue
I'm costumizing my progressbar using the following drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<gradient
android:startColor="@android:color/transparent"
android:endColor="@android:color/transparent" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<gradient
android:startColor="@android:color/white"
android:endColor="@android:color/white" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<gradient
android:startColor="?attr/colorAccent"
android:endColor="?attr/colorAccent" />
</shape>
</clip>
</item>
</layer-list>
When using my app on Android 6 or 7, it works fine but if I try it on Kitkat, the following error is thrown:
android.content.res.Resources$NotFoundException: File res/drawable/quickcontrolsprogress.xml from drawable resource ID #0x7f020094. If the resource you are trying to use is a vector resource, you may be referencing it in an unsupported way. See AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info.
at android.content.res.Resources.loadDrawable(Resources.java:3457)
at android.content.res.Resources.getDrawable(Resources.java:1897)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:374)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:202)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at at.guger.musixs.fragment.ControlsFragment.onCreateView(ControlsFragment.java:86)
...
Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 at android.content.res.TypedArray.getColor(TypedArray.java:327) at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:871) at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:990)
...
The code, the error is pointing at is:
prgqProgress = (ProgressBar) rootView.findViewById(R.id.fr_ctrl_prgqProgress);
prgqProgress.setProgressDrawable(AppCompatResources.getDrawable(getContext(), R.drawable.quickcontrolsprogress)); -> Line 86
Does anyone know why this ResourceNotFound Exception occurs and how to fix it? Thank you!
Solution
It's not a resource not found problem, the error is:
UnsupportedOperationException
: Can't convert to color: type=0x2 at android.content.res.TypedArray.getColor(TypedArray.java:327)
For API < 21 you can't use attributes to color in xml drawable. So only way is to use a reference to a color resource (@color/YOURS_COLOR) or use #RGB format.
Answered By - M. Dhaouadi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.