Androidでvector
を使用する際の問題に直面しています。
API24との電話でテストするときにすべてがうまく働いている間、私はandroid:background="@drawable/ic_blue2"
使用して私のTextview
の背景として画像を表示する(アンドロイドスタジオで輸入SVGから)ベクターを使用しています、起動時にアプリケーションがクラッシュInflateExceptionを伴うAPI22とResources $ NotFoundExceptionを持つ電話機で。
Gradle vectorDrawables.useSupportLibrary = true
に追加するなど前の投稿への回答を試みましたが、機能しませんでした。
私はAndroid Studio 3.0.1とGradle 3.0.1を使用しています。そして、私のアクティビティはAppCompatActivityではなくActivityであることに注意してください(ここで重要かどうかはわかりません)。ここで
は、レイアウトのコードです: https://pastebin.com/DRR5eRm0そして、API22上のエラー(ファイルが大きすぎる)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackgroundWhite"
tools:context="jdev.com.handtwist.MainMenu">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_gray7"
android:orientation="vertical">
<TextView
android:id="@+id/textViewAppname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_blue7"
android:padding="10dp"
android:text="test"
android:textAlignment="center"
android:textColor="@color/colorBackgroundWhite"
android:textSize="36sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="30dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:paddingTop="20dp"
tools:layout_editor_absoluteY="100dp">
<Button
android:id="@+id/buttonSolo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_blue2"
android:padding="10dp"
android:text="@string/solo"
android:textAlignment="center"
android:textColor="@color/colorBackgroundWhite"
android:textSize="24sp" />
<Button
android:id="@+id/buttonMulti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/ic_blue2"
android:padding="10dp"
android:text="@string/multi"
android:textAlignment="center"
android:textColor="@color/colorBackgroundWhite"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical">
<TextView
android:id="@+id/textViewVersion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Version"
android:textAlignment="center"
android:textColor="@color/colorBackgroundWhite" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
私は背景として使用しようとするXMLの例
E/AndroidRuntime: FATAL EXCEPTION: main
Process: jdev.com.handtwist, PID: 4666
java.lang.RuntimeException: Unable to start activity ComponentInfo{jdev.com.handtwist/jdev.com.handtwist.MainMenu}: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3160)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:640)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:450)
at android.app.Activity.setContentView(Activity.java:2400)
at jdev.com.handtwist.MainMenu.onCreate(MainMenu.java:40)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:450)
at android.app.Activity.setContentView(Activity.java:2400)
at jdev.com.handtwist.MainMenu.onCreate(MainMenu.java:40)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-anydpi-v21/ic_gray7.xml from drawable resource ID #0x7f0603a5
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4061)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.loadDrawable(Resources.java:3779)
at android.content.res.TypedArray.getDrawable(TypedArray.java:776)
at android.view.View.<init>(View.java:4001)
at android.view.ViewGroup.<init>(ViewGroup.java:513)
at android.widget.LinearLayout.<init>(LinearLayout.java:199)
at android.widget.LinearLayout.<init>(LinearLayout.java:195)
at android.widget.LinearLayout.<init>(LinearLayout.java:191)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:450)
at android.app.Activity.setContentView(Activity.java:2400)
at jdev.com.handtwist.MainMenu.onCreate(MainMenu.java:40)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-anydpi-v22/$ic_gray7__0.xml from color state list resource ID #0x7f060118
at android.content.res.Resources.twLoadColorStateList(Resources.java:4179)
at android.content.res.Resources.loadColorStateList(Resources.java:4117)
at android.content.res.TypedArray.getColor(TypedArray.java:397)
at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1439)
at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1418)
at android.graphics.drawable.VectorDrawable.inflateInternal(VectorDrawable.java:544)
at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:460)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1192)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1086)
at android.content.res.Resources.loadDraw
私を助けることができる人に感謝します。
編集:ベンのアプローチのエラーを使用しようとすると:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: jdev.com.handtwist, PID: 16157
java.lang.RuntimeException: Unable to start activity ComponentInfo{jdev.com.handtwist/jdev.com.handtwist.MainMenu}: android.content.res.Resources$NotFoundException: File res/drawable-anydpi-v21/ic_testb.xml from drawable resource ID #0x7f0603ce
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3160)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-anydpi-v21/ic_testb.xml from drawable resource ID #0x7f0603ce
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4061)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.getDrawable(Resources.java:1991)
at android.content.res.Resources.getDrawable(Resources.java:1973)
at android.content.Context.getDrawable(Context.java:409)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:351)
at jdev.com.handtwist.MainMenu.onCreate(MainMenu.java:63)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-anydpi-v22/$ic_testb__0.xml from color state list resource ID #0x7f060295
at android.content.res.Resources.twLoadColorStateList(Resources.java:4179)
at android.content.res.Resources.loadColorStateList(Resources.java:4117)
at android.content.res.TypedArray.getColor(TypedArray.java:397)
at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1439)
at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1418)
at android.graphics.drawable.VectorDrawable.inflateInternal(VectorDrawable.java:544)
at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:460)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1192)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1086)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4045)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.getDrawable(Resources.java:1991)
at android.content.res.Resources.getDrawable(Resources.java:1973)
at android.content.Context.getDrawable(Context.java:409)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:351)
at jdev.com.handtwist.MainMenu.onCreate(MainMenu.java:63)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #0: invalid drawable tag gradient
at android.content.res.ColorStateList.twCreateFromXmlInner(ColorStateList.java:176)
at android.content.res.ColorStateList.twCreateFromXml(ColorStateList.java:147)
at android.content.res.Resources.twLoadColorStateList(Resources.java:4175)
at android.content.res.Resources.loadColorStateList(Resources.java:4117)
at android.content.res.TypedArray.getColor(TypedArray.java:397)
at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1439)
at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1418)
at android.graphics.drawable.VectorDrawable.inflateInternal(VectorDrawable.java:544)
at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:460)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1192)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1086)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4045)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.getDrawable(Resources.java:1991)
at android.content.res.Resources.getDrawable(Resources.java:1973)
at android.content.Context.getDrawable(Context.java:409)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:351)
at jdev.com.handtwist.MainMenu.onCreate(MainMenu.java:63)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
res/drawable-anydpi-v21/ic_gray7.xmlを読み込む際に問題があるようです。 v22より上位のAPI用のバージョン(v23など)をお持ちですか?このドロアブルの内容を追加できますか? –
私は他のAPIで(現時点では)テストできません。私は使用しようとするXMLファイルの内容を投稿に追加しました。 –