本文主要是介绍Error inflating class android.support.design.widget.CollapsingToolbarLayout,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
最近在玩材质化,
使用CoordinatorLayout的时候出现这个错误,应该也是对android studio的不了解导致的吧
先贴下运行时候错误代码
第一个错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.android/com.test.android.ui.activity.RandomActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.design.widget.CollapsingToolbarLayoutat android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)at android.app.ActivityThread.access$800(ActivityThread.java:151)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)at android.os.Handler.dispatchMessage(Handler.java:102)at android.os.Looper.loop(Looper.java:135)at android.app.ActivityThread.main(ActivityThread.java:5254)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:903)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.design.widget.CollapsingToolbarLayoutat android.view.LayoutInflater.createView(LayoutInflater.java:633)at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)at android.view.LayoutInflater.inflate(LayoutInflater.java:504)at android.view.LayoutInflater.inflate(LayoutInflater.java:414)at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
。。。等等
出现这个的原因是因为
改成下面的一样的就好了
第二个错误就是
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pszh.materialtest/com.pszh.materialtest.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.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.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
出现这个错误的原因是AndroidManifest的application的theme设置有问题,设置成android:theme="@style/AppTheme"就好了
这篇关于Error inflating class android.support.design.widget.CollapsingToolbarLayout的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!