Xamarin 添加Activity 页面的坑
前言
1、AndroidStudio添加页面时,同时增加了 Activity (代码页) Layout(布局页)
2、Xamarin 添加时是分开添加的所以遇到问题
遇到的问题如下:
Android.Content.ActivityNotFoundException: ‘Unable to find explicit activity class {com.companyname.app2/crc64bb1b55f618e11607.layout1}; have you declared this activity in your AndroidManifest.xml
1、 public class layout1: Activity //这里应该要设置为public
2、类名上增加说明:如下
[Activity(Name = "com.companyname.app2.layout1")]
public class layout1: Activity
3、 布局和代码关联关键代码 (代码页)
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Xamarin.Essentials.Platform.Init(this, bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.layout1); //关联代码
}