BottomSheet automatically opens and closes on activity launch

37 Views Asked by At

My app had a very strange problem of BottomNavigationView of automatically opens and closes within a second. I have already fixed the issue today. I will explain my finding here. It will help someone. I have a bnv in activity and that activity had a fragment. I have tried to use

  android:windowSoftInputMode="adjustPan|adjustResize"

It didn't fixed the issue for me. When i tried

  android:windowSoftInputMode="adjustNothing"

There was a different behavior. The bottom sheet would open and not close automatically. I would have to manually close it.

In my frament i call a Api to fetch data and create recyclerview at runtime in kotlin. by default i would set nestedScrolling to true

  bindingShows.rv.isNestedScrollingEnabled = true

Then I changed it to false. Then, the behavior changed unexpectedly. The bottomsheet would not auto open. I thought i fixed the issue. But when I tap anywhere inside the fragment the bottom sheet would open again. I was like wth? What is causing the problem? Then,by the stroke of luck I actually managed to fixed the issue. But changing the view to FrameLayout from linearLayout in Activity.

1

There are 1 best solutions below

0
Rohaitas Tanoli On

I was using LinearLayout, I just change it to FrameLayout. It fixed the issue for me

        <FrameLayout
        android:id="@+id/bottomSheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#454545"
        android:elevation="@dimen/_10sdp"
        app:behavior_hideable="true"
        app:behavior_peekHeight="@dimen/_50sdp"
        app:behavior_skipCollapsed="false"

        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

In Manifest

 android:configChanges="orientation|layoutDirection|keyboard|keyboardHidden|orientation|screenSize|uiMode"
 android:windowSoftInputMode="adjustPan"