Binary XML file line #1: Error inflating class android.support.design.widget.AppBarLayout

那年仲夏 提交于 2020-01-03 19:37:13

问题


Hello Everyone

There are many threads avilable in this case ... I was tried everything but no luck . I was new to android background..Iam c# guy,now iam work with xamarin droid...So can anyone explain what is the error.this solution not working only **PRE lolipop devices **.

My layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/quickreturn_coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/masonry_grid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

I was Use appcompact Theme

Values/Style.xml

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="Theme.Splash"
    parent="@android:style/Theme.Holo.Light">
    <item name="android:windowBackground">@drawable/splashscreen</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
  </style>

  <style name="AppTheme" parent="Base.Theme">
  </style>
  <style name="Base.Theme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/DarkOrangeLight</item>
    <item name="colorPrimaryDark">@color/DarkOrange</item>
    <item name="colorAccent">@color/DarkOrangeAcent</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="android:windowBackground">@color/bg</item>
    <item name="windowActionBar">false</item>
    <item name="windowActionBarOverlay">false</item>
    <item name="windowNoTitle">true</item>
    <!-- Customize your theme here. -->
  </style>
</resources>

Values-21 \styles.xml

<?xml version="1.0" encoding="utf-8" ?>
<resources>
   <style name="AppTheme" parent="Base.Theme">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@color/DarkOrange</item>
  </style>
</resources>

My Main Activity

protected override void OnCreate(Bundle bundle)
{
            base.OnCreate(bundle);


            try
            {
                SetContentView(Resource.Layout.MansoryLayout);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
}

i got error on setcontentview Method once called ....

Detailed exception IS:

{Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1978/f98871a9/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61 
  at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029 
  at Android.App.Activity.SetContentView (Int32 layoutResID) [0x00070] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/platforms/android-22/src/generated/Android.App.Activity.cs:5500 
  at test.Droid.Activity.MoviesActivity+<OnCreate>d__16.MoveNext () [0x00041] in E:\project\test\test\test\test.Droid\Activity\MoviesActivity.cs:92 
  --- End of managed exception stack trace ---
android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.AppBarLayout
    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.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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
    at md57bfe09fe2721efc565bcf4b957f437a7.MoviesActivity.n_onCreate(Native Method)
    at md57bfe09fe2721efc565bcf4b957f437a7.MoviesActivity.onCreate(MoviesActivity.java:46)
    at android.app.Activity.performCreate(Activity.java:5231)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
    at android.app.ActivityThread.access$800(ActivityThread.java:138)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5095)
    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:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    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)
    ... 23 more
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0b00d9 a=2 r=0x7f0b00d9}
    at android.content.res.Resources.loadDrawable(Resources.java:2068)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
    at android.support.design.widget.AppBarLayout.<init>(AppBarLayout.java:139)

I have added package to my solutions are

Design Support Libiary

Appcompact v7

Appcompact v7 Recyerview

Support libiary V4

i have attached screen shoot of error Message


回答1:


You probably extend Activity not AppCompatActivity. Also, your theme needs a proper parent.

<style name="AppTheme" parent="Theme.AppCompat">

Also make sure you have this call:

protected override void OnCreate(Bundle bundle)
{
    SetTheme(Resource.Style.AppTheme);
    base.OnCreate(bundle)

This solved my problem.




回答2:


complementing Demian you can also use with annotation

[Activity(Theme ="@style/AppTheme")]
public class MainActivity : AppCompatActivity {
    ....
}



回答3:


I had the same problem. And it happened after updating all support library to version 23.4.0.1 from 23.1.1.1. I solved it by downgrading these libraries.



来源:https://stackoverflow.com/questions/32312236/binary-xml-file-line-1-error-inflating-class-android-support-design-widget-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!