pocheshire / BottomNavigationBar

Bottom Navigation Bar for Xamarin
214 stars 70 forks source link

BottomNavigationBar overrides content of the Layout or Fragment it's attached to. #30

Open viestursGr opened 7 years ago

viestursGr commented 7 years ago

I have Navigation Drawer in my application, so I run into issue that Bottom Navigation Bar is above the Navigation Drawer. So, following your suggestion:

All you need to do is instead of attaching the BottomBar to your Activity, attach it to the view that has your content. For example, if your fragments are in a ViewGroup that has the id fragmentContainer

So I did just that:

        protected override void OnCreate(Bundle bundle)
        {
            // Some stuff

            bottomBar = BottomBar.Attach(this.FindViewById<FrameLayout>(Resource.Id.fragmentContainer), bundle);
            bottomBar.SetItems(Resource.Menu.bottombar_menu);
            bottomBar.SetOnMenuTabClickListener(this);
            bottomBar.SetGravity(GravityFlags.Bottom);

            var layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
            layoutParams.Gravity = GravityFlags.Bottom;

            bottomBar.LayoutParameters = layoutParams;
            bottomBar.NoTopOffset();

            // Make a Badge for the first tab, with red background color and a value of "13".
            BottomBarBadge unreadMessages = bottomBar.MakeBadgeForTabAt(0, "#FF0000", 13);

            // Control the badge's visibility
            unreadMessages.Show();
            unreadMessages.Hide();

            // Change the displayed count for this badge.
            unreadMessages.Count = 4;

            // Change the show / hide animation duration.
            unreadMessages.AnimationDuration = 200;

            // If you want the badge be shown always after unselecting the tab that contains it.
            unreadMessages.AutoShowAfterUnSelection = true;

            var fragment = this.FragmentManager.BeginTransaction();
            fragment.AddToBackStack(null);
            fragment.Add(Resource.Id.fragmentContainer, new CustomFragment());
            fragment.Commit();
        }

But unfortunately in result the Bottom Navigation Bar is visible, but the content of Fragment is not.

I checked UI Hierarchy, my fragment content is not even added.

I also tried adding just simple LinearLayout under the view I attached Bottom Navigation Bar, it was also overriden by the Bottom Navigation Bar.

Here is my AXML for main activity view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:minHeight="25px"
    android:fitsSystemWindows="true">
    <android.support.v4.widget.DrawerLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minWidth="25px"
        android:minHeight="25px"
        android:id="@+id/drawer_layout">
      <RelativeLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent">
          <include
              layout="@layout/toolbar"
              android:id="@+id/app_bar"/>
        <ScrollView             
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_below="@id/app_bar">
            <FrameLayout
              android:id="@+id/fragmentContainer"
              android:minWidth="25px"
              android:minHeight="25px"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              />        
        </ScrollView>

        </RelativeLayout>
        <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/nav_menu"
            app:headerLayout="@layout/menu_header" />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

Either I am doing something wrong or in some specific combination of views this issue persists. Looking forward to some explanation why it is happening.

ghost commented 6 years ago

Can you help me with fragments