C# 如何在android C中禁用后退按钮#
我正在用visualstudio中的Xamarin.Android制作一个Android应用程序,我一直在尝试在我的第二个活动中禁用后退按钮,我一直在使用的方法是将此代码添加到活动中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
@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,以下是一些教程:
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();
}
}