Search code examples
androidandroid-fragmentsandroid-viewpagernavigationbar

Android Navigation Bar covering viewpager content


I can't stop the Systems Navigation Bar from covering up my content!

enter image description here

I am scrolled to the very bottom of the recyclerview but its getting hidden behind the navigation bar. Here is my XML layout.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <include layout="@layout/toolbar"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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

<android.support.v4.view.ViewPager
    android:fitsSystemWindows="true"
    android:id="@+id/viewpager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<com.melnykov.fab.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_margin="16dp"
    app:fab_colorNormal="@color/accent"
    app:fab_colorPressed="@color/accent_dark" />

Here is the fragments layout which you are seeing in the picture.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"/>

</FrameLayout>

Ive tried adding android:fitsSystemWindows="true" into every piece of layout I could but that did not work. Other threads mention adding margin calculated from the bar, but that doesn't seem like the proper solution. I grabbed this layout directly from Google's CheesSquare app demo'ing the appbarlayout, and that one looks like its working fine.


Solution

  • I Figured it out. In my particular situation each of my fragments manage their own toolbar instance. I was calling setSupportActionBar() in the onViewCreated() method on my fragments. Moving this functionality into onCreateView() solved it.

        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_my_account, container, false);
            setupToolbar((Toolbar) view.findViewById(R.id.toolbar));
            return view;
        }
    
        private void setupToolbar(Toolbar toolbar) {
            toolbarController.registerToolbar(toolbar);
            toolbarController.setActivityTitle("My Account");
        }
    

    (registerToolbar() calls setSupportActionBar() inside the hosting activity).

    Hope this helps everyone!