我尝试在Xamarin Android中使用导航抽屉,但我遇到了这个问题:
Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.Toolbar
有人可以解释我为什么会收到这个错误吗?我该如何解决?
我已经使用支持库v7:
22.2.0.0 - 23.1.1.1 - 23.2.1 - 24.2.1.0并没有任何帮助我。
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Main content view-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Support V7 Action Bar Drawer Toggle"
android:layout_centerInParent="true"/>
</RelativeLayout>
<!-- The Left Navigation Drawer -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#818181"
android:dividerHeight="1dp"
android:background="#E3F2FD" />
<ListView
android:id="@+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:choiceMode="singleChoice"
android:divider="#E2E2E2"
android:dividerHeight="1dp"
android:background="#9E9E9E" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
MainActivity.cs
using Android.App;
using Android.Widget;
using Android.OS;
using SupportToolbar = Android.Support.V7.Widget.Toolbar;
using Android.Support.V7.App;
namespace LeftDrawable
{
[Activity(Label = "LeftDrawable", MainLauncher = true, Icon = "@drawable/icon",
Theme = "@style/MyTheme")]
public class MainActivity : ActionBarActivity
{
private SupportToolbar toolbar;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
toolbar = FindViewById<SupportToolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
}
}
}