因此,屏幕上有 5 个按钮,您需要确定用户单击了哪个按钮并获取其标签,然后重定向到另一个活动。试图这样做:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetTheme(Android.Resource.Style.ThemeDeviceDefaultLightNoActionBar);
SetContentView(Resource.Layout.MainScreen);
Button BtnHm = (Button)FindViewById(Resource.Id.Home);
BtnHm.Click += SwitchActivity;
Button BtnSrch = (Button)FindViewById(Resource.Id.Search);
BtnSrch.Click += SwitchActivity;
Button BtnLstOfPh = (Button)FindViewById(Resource.Id.ListOfPhotos);
BtnLstOfPh.Click += SwitchActivity;
Button BtnGlr = (Button)FindViewById(Resource.Id.Glory);
BtnGlr.Click += SwitchActivity;
Button BtnMyAcc = (Button)FindViewById(Resource.Id.MyAcc);
BtnMyAcc.Click += SwitchActivity;
}
public void SwitchActivity(object sender, EventArgs e)
{
Button sendBtn = (Button)sender;
switch (sendBtn.Tag)
{
case 1:
Intent toMain = new Intent(this, typeof(MainScreenActivity));
StartActivity(toMain);
break;
case 2:
Intent toSearch = new Intent(this, typeof(SearchActivity));
StartActivity(toSearch);
break;
case 3:
Intent toPhoto = new Intent(this, typeof(ListOfPhotoActivity));
StartActivity(toPhoto);
break;
case 4:
Intent toGlory = new Intent(this, typeof(GloryActivity));
StartActivity(toGlory);
break;
case 5:
Intent toUser = new Intent(this, typeof(UserActivity));
StartActivity(toUser);
break;
}
}
但它在case数字上强调了我,并写道需要一个常数值。怎么修?

您需要为每个按钮分配一个 Id,并在 switch() 构造中,按 id 查找视图元素。例如:
如果这不适合你的编程语言,我希望我的回答能给你一个关于如何解决这个问题的提示。祝你好运)
无论您在 xml 中写入什么,任何值都将被打包到 Tag 属性中(Tag 仍然是一个对象)。当你请求一个属性时,你总会收到一个对象,所以你需要解包:
XAML
XAML.CS
为什么会出现所有这些情况?您还可以为每个按钮创建单独的事件。像这样: