我正在使用Xamarin在我的android项目中使用材质导航抽屉.我一直在尝试将两个Framelayout添加到drawerlayout中,以便我可以从不同的片段切换内容,请参阅下面的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>
Run Code Online (Sandbox Code Playgroud)
主要活动:
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();
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:Android.Views.InflateException:二进制XML文件行#17:错误膨胀类android.support.design.internal.NavigationMenuItemView
我试过在Drawerlayout中移动元素,但错误是持久的.我看过Android文档一切似乎都是正确的.我还检查过我拥有Design和AppCompact库的最新版本
小智 31
我在一段时间内遇到了同样的问题,我不确切知道是什么造成的,但我可以告诉你我做了什么,也许它可以帮助你.
瞧!有效.