Search code examples
c#androidxamarinxamarin.androidmvvmcross

Hiding BottomNavigationBar not working with view set to a GridView


I am using this library to add a BottomNavigationBar to my Xamarin.Android project. I use the BottomBar.AttachShy(CoordinatorLayout, View, Bundle); method to hide the navigation bar when I begin to scroll, but it won't work with my GridView. I scroll the GridView, but the navigation bar persists. Does anyone know what I should do?

Below is my AXML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"                                                                     
    android:id="@+id/myCoordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

  <GridView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnWidth="100dp"
        android:numColumns="auto_fit"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
        android:gravity="center"
        android:textAlignment="center"
        android:id="@+id/menuGrid" />

</android.support.design.widget.CoordinatorLayout>

Here is my C# code:

private BottomBar _bottomBar;

protected override void OnCreate(Bundle bundle) {
     _bottomBar = BottomBar.AttachShy((CoordinatorLayout)FindViewById(Resource.Id.myCoordinator),
                  FindViewById(Resource.Id.menuGrid), bundle);
     _bottomBar.UseFixedMode();

     _bottomBar.SetItems(new[]
               { new BottomBarTab(Resource.Drawable.ic_recents, "Recents"),
                 new BottomBarTab(Resource.Drawable.ic_favorites, "Favorites"),
                 new BottomBarTab(Resource.Drawable.ic_nearby, "Nearby") 
               });
     _bottomBar.MapColorForTab(0, "#7B1FA2");
     _bottomBar.MapColorForTab(1, "#FF5252");
     _bottomBar.MapColorForTab(2, "#FF9800");
}

Solution

  • I fixed this issue for anyone that comes to this post. I had to replace the GridView with a RecyclerView. You will have to implement an Adapter to do this. I used this resource to implement my RecyclerView.