0
我嘗試做導航視圖和DrawerLayout導航Android中Xamarin(C#)
這裏是我的axml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- your content layout -->
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/nav_view"
app:menu="@menu/nav_menu"/>
</android.support.v4.widget.DrawerLayout>
這裏是我的活動:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using MvvmCross.Droid.Views;
using Android.Support.V4.Widget;
using Android.Support.Design.Widget;
using Android.Content.PM;
namespace TieiT.Droid.Views
{
[Activity(Label = "GeneralInfo", ScreenOrientation = ScreenOrientation.Portrait)]
public class GeneralInfo : MvxActivity
{
DrawerLayout drawerLayout;
NavigationView navigationView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.GeneralInfo);
// Create your application here
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
navigationView.NavigationItemSelected += (sender, e) =>
{
e.MenuItem.SetChecked(true);
//react to click here and swap fragments or navigate
drawerLayout.CloseDrawers();
};
}
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);
}
}
}
我有那些錯誤:
Error CS0103 The name 'SupportActionBar' does not exist in the current context TieiT.Droid F:\Conf\TieiT.Core\TieiT.Droid\Views\GeneralInfo.cs 31 Active
Error CS0103 The name 'SupportActionBar' does not exist in the current context TieiT.Droid F:\Conf\TieiT.Core\TieiT.Droid\Views\GeneralInfo.cs 32 Active
Error CS0103 The name 'SetSupportActionBar' does not exist in the current context TieiT.Droid F:\Conf\TieiT.Core\TieiT.Droid\Views\GeneralInfo.cs 30 Active
Error CS0117 'Resource.Id' does not contain a definition for 'drawer_layout' TieiT.Droid F:\Conf\TieiT.Core\TieiT.Droid\Views\GeneralInfo.cs 34 Active
也許t這裏是愚蠢的問題,但我是新手。 我如何解決這些錯誤?
感謝您的回答和幫助。