Reputation: 161
I am using a material navigation drawer in my android project using Xamarin. I have been trying to add two Framelayouts into the drawerlayout so that I can switch the content from different fragments see below 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>
The main activity :
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();
}
I get the following error: Android.Views.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView
I have tried moving the elements in the Drawerlayout but the error is persistent. I have looked at the Android documentation everything seems correct. I have also checked that I have the most recent version of both the Design and AppCompact library
Upvotes: 9
Views: 10944
Reputation: 7
I fixed it by right clicking android project -> Properties -> Android Options and selecting nothing at the Code shrinker.
Upvotes: 0
Reputation: 13
I just had this issue. All I needed to do was Right click on my Android solution → Properties → Android Options → set Linking to None.
Upvotes: 0
Reputation: 8036
Just cleaning the solution wasn't enough for me; I had to manually remove everything in the bin and obj folders to get up and running again.
Upvotes: 0
Reputation: 23
A quick remark regarding the exception: The exception occurs also if no content layout has been added to the DrawerLayout
, so be sure to add one.
An example:
<?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/activity_main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Start of content -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/toolbar"
android:id="@+id/toolbar" />
</LinearLayout>
<!-- End of content -->
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/activity_main_navigation_view"
app:menu="@menu/menu_activity_main_navigation" />
</android.support.v4.widget.DrawerLayout>
Upvotes: 1
Reputation: 69
I try my solution and it did running success: 1. Clear temp on disk C(disk setup opera system) 2. Rebuild project 3. Insert in to head activity [Activity(Theme = "@style/MyTheme")] public class viewDetailsActivity : BaseActivity {.....} 4. Running Project Note: insert file style.xml this code
<style name="MyTheme" parent="MyTheme.Base">
<item name="android:textColor">@color/black</item>
</style>
<!-- Base theme applied no matter what API -->
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/primary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/primaryDark</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated-
colorControlHighlight and colorSwitchThumbNormal. -->
<!-- Option to hide the drop shadow here
<item name="actionBarStyle">@style/MyTheme.ActionBar</item>
<item name="android:windowContentOverlay">@null</item>
-->
</style>
<style name="MyTheme.NoActionBar">
<!-- Both of these are needed -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyTheme.ActionBar" parent="style/Widget.AppCompat.Light.ActionBar.Solid">
<!-- remove shadow below action bar -->
<!-- <item name="android:elevation">0dp</item> -->
<!-- Support library compatibility -->
<item name="elevation">0dp</item>
<item name="android:background">@color/pictonBlue</item>
</style>
I think i talk English not good, but problem solve success
Upvotes: 1
Reputation:
The error is because you might be extending your MainActivity
by Activity
instead of AppComptActivity
If you are using any of the Design Library components, you should ensure your activity extends AppCompatActivity and uses an appropriate Theme.AppCompat theme. Note that the FloatingActionButton
relies on the colorAccent
set on your theme - ensure your theme has that defined.
Upvotes: 2
Reputation: 99
I may be late, but i just got the same error. So on AndroidStudio, i just cleaned my project ("Clean Projet"). After that i was able to run my project once again without that error.
Upvotes: 7
Reputation: 512
I was facing the same problem some time back, I don't know exactly what caused it, but I can tell you what I did, maybe it can help you.
Voila! It worked.
Upvotes: 30