问题
My app recently started to crash on any activity or fragment that has a CollapsingToolbarLayout with the following error log:
`
Unable to start activity ComponentInfo{com.radioafrica.music/com.radioafrica.music.activity.PlaylistTracks}: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class android.support.design.widget.CollapsingToolbarLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NoSuchMethodError: No static method setLayoutDirection(Landroid/graphics/drawable/Drawable;I)V in class Landroid/support/v4/graphics/drawable/DrawableCompat; or its super classes (declaration of 'android.support.v4.graphics.drawable.DrawableCompat' appears in /data/data/com.radioafrica.music/files/instant-run/dex/slice-com.android.support-support-v4-24.0.0-beta1_f8cf3ba4c70f87f407a745b9fa14a2205d0b587c-classes.dex)
at android.support.design.widget.CollapsingToolbarLayout.setStatusBarScrim(CollapsingToolbarLayout.java:663)
at android.support.design.widget
`
When i comment out collapsingToolbarLayout.setStatusBarScrim(color); , it works fine, but the downside is that i cant set a scrim color and the title doesnt show on the toolbar. Is this a bug with the support library?
回答1:
I managed to get rid of the error by going through my build.gradle file and removing any dependency that might have another version of the v4 support library. It seems that the conflicting versions of the libraries were the problem.
回答2:
I got the same error and long time stared on my dependencies versions.
Then I try remove this line and everything works fine. But I do’t understand the reason, sorry.
compile "com.android.support:support-v4:+
来源:https://stackoverflow.com/questions/37395138/error-when-setting-contentscrim-color-on-collapsingtoolbarlayout