尝试在xamarin表单应用程序中运行此代码时,出现以下异常:
Android.Content.Res.Resources + NotFoundException:无法找到资源ID#0x1
[Activity(Label = "Xamarin Forms", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.main);
Toolbar toolbar = this.FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
...
如果我从AppCompatActivity继承而不是应用程序没有崩溃,但表单apis不再可用。
这是我的布局文件,以防它有用:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/main_content"
android:layout_below="@id/toolbar" />
</RelativeLayout>