c# - 二进制 XML 文件行 #1 : Error inflating class android. support.design.widget.AppBarLayout

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

大家好

在这种情况下有很多线程可用...我尝试了所有方法但没有运气。 我是 android 背景的新手..我是 c# 人,现在我正在使用 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

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

enter image description here

最佳答案

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

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

还要确保你有这个电话:

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

这解决了我的问题。

关于c# - 二进制 XML 文件行 #1 : Error inflating class android. support.design.widget.AppBarLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32312236/

相关文章:

C#:如何将完整的 ContextMenu 添加到 MenuItem 作为子菜单

c# - 多次播放后 MediaElement 失败

listview - Android 单声道中的 AddTextChangedListener

android - 如何在 CollapsingToolbarLayout android 中设置子标题

android - 特定 fragment 中的 Snackbar

c# - 事件监听器的目的是什么?

android - 在 XML 中的自定义 ScrollView 上膨胀类时出错?

android - Google OAuth Android 的重定向 url

android - 当 RecyclerView 为空时阻止工具栏折叠

c# - 嵌套的Json反序列化c#