无法充气布局" android.support.design.widget.NavigationView"

时间:2017-12-07 12:12:34

标签: android xamarin.android

我从这里复制了一个教程: http://www.c-sharpcorner.com/article/xamarin-android-create-left-drawer-layout/ 但我无法编译。我收到这个错误:

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

Visual Studio中的Designer,在运行之前,会给我 这个错误:

You need to use a Theme.App.Compat theme (or descendant) of the design library.

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="#33B86C"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:layout_width="match_parent">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_height="match_parent"
            android:layout_width="200dp"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:menu="@menu/menu" />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

这是我的班级:

[Activity(Label = "test", Theme = 

"@style/Theme.AppCompat.Light.NoActionBar")]
    public class test : AppCompatActivity
    {
        DrawerLayout drawerLayout;
        NavigationView navigationView;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Test);
            var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetDisplayShowTitleEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(true);
            SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.btn_bookoflifeMainMenu);
            drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
            navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
        }
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
                case Android.Resource.Id.Home:
                    drawerLayout.OpenDrawer(Android.Support.V4.View.GravityCompat.Start);
                    return true;
            }
            return base.OnOptionsItemSelected(item);
        }
    }

当我取消抽屉的充气时,它会正确编辑,但是 - 显然 - 我没有获得导航视图。

有人可以帮我吗?我一直在滚动浏览这个帖子很多,没有任何帮助。

0 个答案:

没有答案