C# 如何在android C中禁用后退按钮#

C# 如何在android C中禁用后退按钮#,c#,android,visual-studio,xamarin,xamarin.android,C#,Android,Visual Studio,Xamarin,Xamarin.android,我正在用visualstudio中的Xamarin.Android制作一个Android应用程序,我一直在尝试在我的第二个活动中禁用后退按钮,我一直在使用的方法是将此代码添加到活动中 @Override public void onBackPressed() { } 所以代码应该是这样的 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App

我正在用visualstudio中的Xamarin.Android制作一个Android应用程序,我一直在尝试在我的第二个活动中禁用后退按钮,我一直在使用的方法是将此代码添加到活动中

@Override
public void onBackPressed() {
}
所以代码应该是这样的

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 Java.Lang;

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

            SetContentView(Resource.Layout.easyQuiz);

            // Create your application here

        }

        @Override
public void onBackPressed()
        {
            //Include the code here
            return;
        }

    }
}
但这给了我一个错误:

member modifier 'public' must precede the member type and name
我假设这是因为我用C语言做这个项目,既然我用C语言而不是Java(android开发的新手),那么正确的解决方案是什么呢


我在学习时试图避免StackOverflow,但在C#

中很难在线找到Android开发的参考资料在C#中进行覆盖的正确方法是:


例如,如果是登录页面(活动):

选中此项:

关于使用Xamarin开发android,以下是一些教程:


你到底为什么要用C#做Android开发?您是否正在使用Xamarin(或试图)?onBackPressed方法是公共的。不能使修改器更受限制,但可以使其更宽松。例如,如果你扩展了一个有受保护方法的类,你可以将该方法公开,但是,如果超类有一个公开的方法,你的子类就不能将其私有化(或受保护或包保护)。@Demitrian Im使用Visual Studio作为我的IDE,我已经用C#编程一年多了,而且我也不想突然改变主意Java@VargaDev但是你用的是什么框架?从你的帖子上看不太清楚。如果不使用任何框架,就不能直接用C#编写Android应用程序。它不会编译。Xamarin,我不认为VS支持dot42,但不确定。这很有帮助!但是我需要找出如何“Null”掉按钮,我基本上想在第二个活动中禁用back按钮
  public override void OnBackPressed()
  {
        //Include the code here
        return;
  }
public override void OnBackPressed(){
 //by this way.. user want be able to hit the back button 
 // unless user is logged in

     if (user.IsLoggedIn()){
         base.OnBackPressed();
      }
}