Visual studio VS Android应用程序(Xamarin)导航抽屉应用程序-添加活动

Visual studio VS Android应用程序(Xamarin)导航抽屉应用程序-添加活动,visual-studio,xamarin.android,Visual Studio,Xamarin.android,我使用VS2017创建了一个Android应用程序(Xamarin)导航抽屉应用程序。我在互联网上搜索了一个示例,说明如何向使用已创建的导航抽屉但未成功的应用程序添加新活动。有没有关于如何添加活动的想法 谢谢 保罗 public bool OnNavigationItemSelected(IMenuItem) { int id=item.ItemId; if(id==Resource.id.nav\u摄像机) { //在这里运行一个新的活动! } else if(id==Resource.id.

我使用VS2017创建了一个Android应用程序(Xamarin)导航抽屉应用程序。我在互联网上搜索了一个示例,说明如何向使用已创建的导航抽屉但未成功的应用程序添加新活动。有没有关于如何添加活动的想法

谢谢 保罗

public bool OnNavigationItemSelected(IMenuItem)
{
int id=item.ItemId;
if(id==Resource.id.nav\u摄像机)
{
//在这里运行一个新的活动!
}
else if(id==Resource.id.nav_gallery)
{
}
else if(id==Resource.id.nav_幻灯片)
{
}
else if(id==Resource.id.nav\u manage)
{
}
else if(id==Resource.id.nav_share)
{
}
else if(id==Resource.id.nav_send)
{
}
抽屉布局抽屉=FindViewById(Resource.Id.drawer\u布局);
抽屉。关闭抽屉(重力压缩机启动);
返回true;
}
从中,您可以看到:

如果应用程序根据用户选择的导航菜单项来切换内容,则应考虑在主内容区域中使用片段。从导航抽屉导航时交换片段可以实现无缝抽屉动画,因为相同的基本布局保持不变

官方建议我们在主要内容区域使用片段

如果要启动新活动,需要创建活动并为其创建布局,如
Activity1

[Activity(Label = "Activity1")]
public class Activity1 : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your application here

        SetContentView(Resource.Layout.layout1);
    }
}
布局1

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="new Activity" />
</LinearLayout>

这将打开一个新活动,在新活动中,没有
抽屉布局

如果单击按钮,是否要启动活动?是的,我想启动导航抽屉项目上的活动单击。我是Xamarin Android的新手,所以我猜一个活动就是另一个页面?你测试过我的答案了吗?如果你想转到另一个页面,你需要在你的项目中创建一个新的活动。您好,仍然不能解决你的问题吗?也许可以帮助你。您好,我在c#中发布了一个示例。我以前尝试过类似于您上面的代码,导航抽屉确实消失了。你有C#中的片段示例吗?是的,如果你开始一个新活动,导航抽屉将消失,因为
DrawerLayout
存在于你的第一个活动中,而不是你的新活动中。关于片段示例,你可以阅读,我认为你应该打开另一个线程,询问如何使用
DrawerLayout
切换片段。顺便说一句,如果我的答案对你有帮助,请接受它作为答案,谢谢。你可以通过阅读来理解活动和片段之间的区别。谢谢Joe Lv,你的GitHub示例正是我想要的,我认为VS模板应该包含这段代码。保罗。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="new Activity" />
</LinearLayout>
if (id == Resource.Id.nav_camera)
{
    Intent intent = new Intent(this, typeof(Activity1));
    StartActivity(intent);
}