【问题标题】:Binary XML file line #1: Error inflating class android.support.design.widget.AppBarLayout二进制 XML 文件第 1 行:膨胀类 android.support.design.widget.AppBarLayout 时出错
【发布时间】:2015-08-31 13:18:03
【问题描述】:

大家好

在这种情况下有很多线程可用...我尝试了所有方法,但没有运气。 我是 android 背景的新手..我是 c# 的家伙,现在 iam 与 xamarin droid 一起工作...所以任何人都可以解释什么是错误。这个解决方案仅适用于 **PRE lolipop 设备**。

我的布局

<?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>

我是使用 appcompact 主题

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>

我的主要活动

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


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

我在调用 setcontentview 方法时遇到错误 ....

详细的异常是:

{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)

我已将包添加到我的解决方案中

Design Support Libiary

Appcompact v7

Appcompact v7 Recyerview

Support libiary V4

我已附上错误消息的屏幕截图

【问题讨论】:

    标签: c# xamarin.android android-design-library


    【解决方案1】:

    您可能扩展 Activity 而不是 AppCompatActivity。 此外,您的主题需要一个合适的父级。

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

    还要确保你有这个电话:

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

    这解决了我的问题。

    【讨论】:

      【解决方案2】:

      补充 Demian,您也可以使用注释

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

      【讨论】:

      • 我使用的是FormsAppCompatActivity,结果实际上摆脱了Theme="@style/MyTheme" 的工作!
      【解决方案3】:

      我遇到了同样的问题。它发生在将所有支持库从 23.1.1.1 更新到版本 23.4.0.1 之后。我通过降级这些库来解决它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-06
        • 1970-01-01
        • 2016-11-16
        • 1970-01-01
        • 2016-01-12
        • 2016-11-02
        • 2018-03-04
        相关资源
        最近更新 更多