0

I get a error message if I try to call a snackbar by tapping on a floating action button.

This is the error message I get:

Android.Views.InflateException: Binary XML file line #18: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true

With a NavigationView it works fine but I want to get it run without a Navigation View

This is my code:

Main.axml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer">
 <LinearLayout 
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:padding="10dip">
   <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
     <EditText
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:hint="First Name" />
   </android.support.design.widget.TextInputLayout>
   <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
      <EditText
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:hint="Last Name" />
   </android.support.design.widget.TextInputLayout>
  </LinearLayout>
 <android.support.design.widget.FloatingActionButton
        android:id="@+id/ActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="10dip"
        app:backgroundTint="@android:color/holo_green_light"
        android:src="@drawable/icon" />
 </android.support.design.widget.CoordinatorLayout>

MainActivity.cs

using Android.App;
using Android.OS;
using Android.Widget;
using Android.Support.Design.Widget;
using Android.Support.V4.Widget;
using Android.Support.V7.App;
using toolbar = Android.Support.V7.Widget.Toolbar;

namespace FloatingActionButtonExample
{
    [Activity(Label = "FloatingActionButtonExample", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/Theme.AppCompat.Light.DarkActionBar")]
    public class MainActivity : AppCompatActivity
    {


        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            var container = FindViewById<CoordinatorLayout>(Resource.Id.drawer);
            var actionButton = FindViewById<FloatingActionButton>(Resource.Id.ActionButton);

            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);

            actionButton.Click += (sender, e) =>
                Snackbar.Make(container, "FAB Tapped!", Snackbar.LengthLong)
                    .SetAction("Action", view =>
                        Toast.MakeText(this, "Action tapped!", ToastLength.Short).Show())
                    .Show();
        }

    }
}

I've tried many options but nothing worked for me.

WeSt
  • 889
  • 5
  • 14
  • 32
  • 1
    I made a basic demo using your codes, but didn't receive the error message, could you please share a basic demo that can reproduce the problem? – Elvis Xia - MSFT Apr 12 '17 at 05:53
  • Thanks for your answer. Before I posted this, I made a couple clean and build but stock on the same error. Today I made one clean and build and now it works fine. So many hours wasted... – WeSt Apr 12 '17 at 09:50

0 Answers0