gpt4 book ai didi

java - 设置进度条不确定 srcCompat

转载 作者:行者123 更新时间:2023-11-29 02:35:36 25 4
gpt4 key购买 nike

我制作了自己的 progressBar,这样我就可以在 pre-lolipop 中着色,并且在我将可绘制对象从 png 更改为 vector 之前效果很好。我收到长堆栈跟踪错误。正如我在谷歌上搜索的那样,错误是因为我使用 src 而不是 srcCompat。但是我没有找到任何方法在 progressBar 的不确定可绘制对象中使用 srcCompat。那么请您告诉我如何将 srcCompat 用于我的不确定性?

XML:

<com.muadzbinjabal.muadzbinjabal.helper.view.TintProgressBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminateDrawable="@drawable/xml_progress_bar_circle"
style="@style/Widget.AppCompat.ProgressBar"/>

xml_progress_bar_circle:

<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_progress_bar"
android:pivotX="50%"
android:pivotY="50%"/>

ic_progress_bar :

<vector android:height="24dp" android:viewportHeight="80.433334"
android:viewportWidth="80.433334" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillAlpha="0.18" android:fillColor="#00000000"
android:fillType="evenOdd"
android:pathData="M75.21,40.22A34.99,34.99 0,0 1,53.61 72.55,34.99 34.99,0 0,1 15.47,64.96 34.99,34.99 0,0 1,7.89 26.83,34.99 34.99,0 0,1 40.22,5.23"
android:strokeAlpha="0.99" android:strokeColor="#000000"
android:strokeLineCap="round" android:strokeLineJoin="round" android:strokeWidth="8.37210464"/>
</vector>

错误:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.muadzbinjabal.muadzbinjabal, PID: 18996
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.muadzbinjabal.muadzbinjabal/com.muadzbinjabal.muadzbinjabal.ActivityRegister}: android.view.InflateException: Binary XML file line #0: Error inflating class com.muadzbinjabal.muadzbinjabal.helper.view.TintProgressBar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.muadzbinjabal.muadzbinjabal.helper.view.TintProgressBar
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.muadzbinjabal.muadzbinjabal.BaseActivity_Network.onCreate(BaseActivity_Network.kt:37)
at com.muadzbinjabal.muadzbinjabal.ActivityRegister.onCreate(ActivityRegister.kt:73)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
at android.app.ActivityThread.access$800(ActivityThread.java:139) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:149) 
at android.app.ActivityThread.main(ActivityThread.java:5257) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.muadzbinjabal.muadzbinjabal.BaseActivity_Network.onCreate(BaseActivity_Network.kt:37) 
at com.muadzbinjabal.muadzbinjabal.ActivityRegister.onCreate(ActivityRegister.kt:73) 
at android.app.Activity.performCreate(Activity.java:5411) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
at android.app.ActivityThread.access$800(ActivityThread.java:139) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:149) 
at android.app.ActivityThread.main(ActivityThread.java:5257) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/xml_progress_bar_circle.xml from drawable resource ID #0x7f070090
at android.content.res.Resources.loadDrawable(Resources.java:2163)
at android.content.res.Resources.loadDrawable(Resources.java:2082)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ProgressBar.<init>(ProgressBar.java:294)
at android.widget.ProgressBar.<init>(ProgressBar.java:246)
at android.widget.ProgressBar.<init>(ProgressBar.java:242)
at com.muadzbinjabal.muadzbinjabal.helper.view.TintProgressBar.<init>(TintProgressBar.kt:23)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.muadzbinjabal.muadzbinjabal.BaseActivity_Network.onCreate(BaseActivity_Network.kt:37) 
at com.muadzbinjabal.muadzbinjabal.ActivityRegister.onCreate(ActivityRegister.kt:73) 
at android.app.Activity.performCreate(Activity.java:5411) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
at android.app.ActivityThread.access$800(ActivityThread.java:139) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:149) 
at android.app.ActivityThread.main(ActivityThread.java:5257) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_progress_bar.xml from drawable resource ID #0x7f07007d
at android.content.res.Resources.loadDrawable(Resources.java:2163)
at android.content.res.Resources.loadDrawable(Resources.java:2082)
at android.content.res.Resources.getDrawable(Resources.java:706)
at android.graphics.drawable.RotateDrawable.inflate(RotateDrawable.java:247)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2159)
at android.content.res.Resources.loadDrawable(Resources.java:2082) 
at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 
at android.widget.ProgressBar.<init>(ProgressBar.java:294) 
at android.widget.ProgressBar.<init>(ProgressBar.java:246) 
at android.widget.ProgressBar.<init>(ProgressBar.java:242) 
at com.muadzbinjabal.muadzbinjabal.helper.view.TintProgressBar.<init>(TintProgressBar.kt:23) 
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.muadzbinjabal.muadzbinjabal.BaseActivity_Network.onCreate(BaseActivity_Network.kt:37) 
at com.muadzbinjabal.muadzbinjabal.ActivityRegister.onCreate(ActivityRegister.kt:73) 
at android.app.Activity.performCreate(Activity.java:5411) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
at android.app.ActivityThread.access$800(ActivityThread.java:139) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:149) 
at android.app.ActivityThread.main(ActivityThread.java:5257) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #0: invalid drawable t

最佳答案

要使用 srcCompat,你必须在下面使用它

app:srcCompat="@drawable/ic_play"

将其添加到顶部父 View 。

xmlns:app="http://schemas.android.com/apk/res-auto"

关于java - 设置进度条不确定 srcCompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47320869/

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