gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:36:35 25 4
gpt4 key购买 nike

大家好

在这种情况下有很多线程可用...我尝试了所有方法但没有运气。我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com