CollapsingToolbarLayout 不工作应用程序崩溃

CollapsingToolbarLayout is not working app crash

如果我将依赖项从 23.1.1 更新到 23.2.0,CollapsingToolbarLayout 将无法正常工作。应用崩溃并抛出错误。

java.lang.RuntimeException:android.view.InflateException: Binary XML file line #77: Binary XML file line #77: Error inflating class android.support.design.widget.CollapsingToolbarLayout
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
                                                                                      at android.app.ActivityThread.access00(ActivityThread.java:229)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:148)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:7331)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                                   Caused by: android.view.InflateException: Binary XML file line #77: Binary XML file line #77: Error inflating class android.support.design.widget.CollapsingToolbarLayout
                                                                                      at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
                                                                                      at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                                      at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
 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/app/in.passionconnect.application-1/base.apk)

依赖项看起来像这样

compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:cardview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'

和我的 compileSdkVersion 23 buildToolsVersion "23.0.2"

尝试将依赖项 com.android.support.*** 更新到最新版本。这可能会有所帮助。

你可以试试稳定版 24.2.0'

步骤 1

compileSdkVersion 24
buildToolsVersion "24.0.2"

步骤 2

 targetSdkVersion 24

然后

步骤 3

 compile 'com.android.support:appcompat-v7:24.2.0'
 compile 'com.android.support:design:24.2.0'

最后 清理-重建-Gradle & 运行 .