0

When I try to use SwipeRefreshLayout with a BottomAppBar then the fragment shows no conent and the SwipeRefresh feature is not there. I also implemented it in a normal activity with an TopAppBar and it worked finde. Nevertheless, when I use the BottomAppBar nothing worked for me. I already spent hours of trying to solve this.

I already tried: Link1 Link2

Thanks for help!

My code:

Activity:

<androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ui.main.MainActivity">


        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.core.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <fragment
                    android:id="@+id/nav_host_main"
                    android:name="androidx.navigation.fragment.NavHostFragment"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:defaultNavHost="true"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:navGraph="@navigation/main_navigation" />
            </androidx.core.widget.NestedScrollView>

            <com.google.android.material.bottomappbar.BottomAppBar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                app:menu="@menu/main"
                app:hideOnScroll="true"
                app:navigationIcon="@drawable/ic_menu_24dp" />


        </androidx.coordinatorlayout.widget.CoordinatorLayout>


        <com.google.android.material.navigation.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>

Fragment: also tryed it with a T

<androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/homeFragmentLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">


    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test" />
        </RelativeLayout>
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Result: Screenshot

kaulex
  • 2,921
  • 3
  • 11
  • 38

1 Answers1

0

Found the solution: The problem is that the nav_host_fragment is in a NestedScrollView. The SwipeToRefreshLayout can't be in a scrollview with in another ScrollView.

        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">


            <fragment
                android:id="@+id/nav_host_main"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:defaultNavHost="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:navGraph="@navigation/main_navigation" />


            <com.google.android.material.bottomappbar.BottomAppBar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                app:menu="@menu/main"
                app:hideOnScroll="true"
                app:navigationIcon="@drawable/ic_menu_24dp" />


        </androidx.coordinatorlayout.widget.CoordinatorLayout>


        <com.google.android.material.navigation.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
    </androidx.drawerlayout.widget.DrawerLayout>
kaulex
  • 2,921
  • 3
  • 11
  • 38