gpt4 book ai didi

java - 使用 Android 4.4.4 找不到可绘制资源

转载 作者:行者123 更新时间:2023-12-02 12:43:42 25 4
gpt4 key购买 nike

我正在使用以下可绘制对象来定制我的进度条:

<?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>

在 Android 6 或 7 上使用我的应用程序时,它工作正常,但如果我在 Kitkat 上尝试,则会引发以下错误:

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)
...

错误指向的代码是:

prgqProgress = (ProgressBar) rootView.findViewById(R.id.fr_ctrl_prgqProgress);
prgqProgress.setProgressDrawable(AppCompatResources.getDrawable(getContext(), R.drawable.quickcontrolsprogress)); -> Line 86

有谁知道为什么会发生此 ResourceNotFound 异常以及如何修复它?谢谢!

最佳答案

这不是资源未找到的问题,错误是:UnsupportedOperationException:无法转换为颜色:在 android.content.res.TypedArray.getColor(TypedArray.java:327) 处 type=0x2

对于 API < 21,您不能使用属性在 xml 可绘制对象中着色。因此唯一的方法是使用对颜色资源的引用 (@color/YOURS_COLOR) 或使用 #RGB 格式。

关于java - 使用 Android 4.4.4 找不到可绘制资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44861370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com