locked
Snackbar and FAB RRS feed

  • Question

  • User255367 posted

    Hi,

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

    Error Message:

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

    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.

    Tuesday, April 11, 2017 4:02 PM

Answers

  • User207279 posted

    @xWeST The sample code which you have posted works fine. Error seems to be with Using Merge as root tag in your layout file. Please check it

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, April 12, 2017 9:06 AM
  • User255367 posted

    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...

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, April 12, 2017 9:49 AM

All replies

  • User207279 posted

    @xWeST The sample code which you have posted works fine. Error seems to be with Using Merge as root tag in your layout file. Please check it

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, April 12, 2017 9:06 AM
  • User255367 posted

    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...

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, April 12, 2017 9:49 AM