尝试扩充协调器布局时出错

时间:2016-04-06 14:28:32

标签: xamarin xamarin.android mvvmcross

当我尝试将布局扩展到包含协调器布局的主活动时,我收到此异常:

04-06 16:18:17.434 I/mono-stdout( 2690): InnerException was IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
    04-06 16:18:17.434 I/mono-stdout( 2690):      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
    04-06 16:18:17.435 I/mono-stdout( 2690):   at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029 
    04-06 16:18:17.435 I/mono-stdout( 2690):   at Android.Runtime.JNIEnv.FinishCreateInstance (IntPtr instance, IntPtr jclass, IntPtr constructorId, Android.Runtime.JValue* constructorParameters) [0x0000b] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:306 
    04-06 16:18:17.435 I/mono-stdout( 2690):   at Android.Support.Design.Widget.CoordinatorLayout..ctor (Android.Content.Context context, IAttributeSet attrs) [0x000f9] in <filename unknown>:0 
    04-06 16:18:17.435 I/mono-stdout( 2690):   at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
    04-06 16:18:17.435 I/mono-stdout( 2690):   at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644 
    04-06 16:18:17.435 I/mono-stdout( 2690):   --- End of managed exception stack trace ---
    04-06 16:18:17.436 I/mono-stdout( 2690): java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
    04-06 16:18:17.436 I/mono-stdout( 2690):    at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34)
    04-06 16:18:17.436 I/mono-stdout( 2690):    at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:182)
    04-06 16:18:17.436 I/mono-stdout( 2690):    at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:176)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at md5bf0126c95bf9fc0db24c02c9adb4cfa7.MvxLayoutInflater_PrivateFactoryWrapper2.n_onCreateView(Native Method)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at md5bf0126c95bf9fc0db24c02c9adb4cfa7.MvxLayoutInflater_PrivateFactoryWrapper2.onCreateView(MvxLayoutInflater_PrivateFactoryWrapper2.java:31)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at moneyfox.droid.activities.MainActivity.n_onCreate(Native Method)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at moneyfox.droid.activities.MainActivity.onCreate(MainActivity.java:30)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.Activity.performCreate(Activity.java:6237)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.os.Handler.dispatchMessage(Handler.java:102)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.os.Looper.loop(Looper.java:148)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread.main(ActivityThread.java:5417)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at java.lang.reflect.Method.invoke(Native Method)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    Unhandled Exception:

    Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout

但我已经使用了AppCompat主题:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

主要活动的布局:

xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_frame"
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true" />
    </android.support.design.widget.CoordinatorLayout>
    <FrameLayout
        android:id="@+id/navigation_frame"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="left|start" />
</android.support.v4.widget.DrawerLayout>

另外我发现发帖的人我要设置windowActionBar和windowNoTitle标签,我已经做过了。

整个代码基于mvvm交叉回购中的样本。

有趣的是,我发现当我更新到support.design包的新版本时,错误开始出现。 有什么办法可以避免这种情况吗?

1 个答案:

答案 0 :(得分:0)

我发现了问题..我没有添加MvvmCross.Droid.Support.Design Nuget Package ...

https://www.nuget.org/packages/MvvmCross.Droid.Support.Design/

添加之后,清理解决方案并重新启动VS它有效..