【发布时间】:2020-06-12 21:50:17
【问题描述】:
我正在使用 Xamarin 的 android 项目中使用材质导航抽屉。 我一直在尝试将两个 Framelayouts 添加到抽屉布局中,以便我可以从不同的片段切换内容,请参见下面的 xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The ActionBar displayed at the top -->
<include
layout="@layout/toolbar"
android:id="@+id/toolbar" />
<!-- The main content view where fragments are loaded -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="@+id/scrollview">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/search_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/blah"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/drawer_view"
app:itemTextColor="#FFFFFF"
app:itemIconTint="#FFFFFF"
android:background="#464646"/>
</android.support.v4.widget.DrawerLayout>
主要活动:
protected override void OnCreate(Android_OS.Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
// Setting up the toolbar
var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
SupportActionBar.SetTitle(Resource.String.ApplicationName);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
SupportActionBar.SetDisplayShowHomeEnabled(true);
// Attach item selected handler to navigation view
var navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;
// Create ActionBarDrawerToggle button and add it to the toolbar
var drawerToggle = new Android_Support.V7.App.ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.open_drawer, Resource.String.close_drawer);
drawerLayout.SetDrawerListener(drawerToggle);
drawerToggle.SyncState();
}
我收到以下错误:Android.Views.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView
我已尝试移动 Drawerlayout 中的元素,但错误仍然存在。我查看了 Android 文档,一切似乎都是正确的。我还检查了我是否拥有最新版本的 Design 和 AppCompact 库
【问题讨论】:
-
它可能会帮助您github.com/chrisbanes/cheesesquare,下载此项目并运行,按照相同的方法并根据您的要求更改代码。希望这对您有所帮助。
-
尝试清理并重建,看看是否能解决问题。在进行需要重新生成资源的更改后,我偶尔会收到类似的错误。重建后,它对我来说就消失了。
-
清理和重建似乎不能解决问题。
-
干净和重建对我有用。
-
Clean + Build 也对我有用。