49

I have a BottomSheet in my Activity.

I'm calling behavior.setState(BottomSheetBehavior.STATE_EXPANDED); to show the bottom sheet and it works fine, but the problem I have is that I can somehow click on the empty space of my bottom sheet to trigger onClick event of a view that is behind the bottom sheet.

Is there a way to prevent this from happening?

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
user1865027
  • 3,505
  • 6
  • 33
  • 71

2 Answers2

68

A simple solution is to add the

android:clickable="true"

attribute to the layout that you are using for your bottom sheet. That way it will capture all clicks, and not let them bleed through. You do not have to set an onClick method for it, as you have no need to handle them.

Shihab Uddin
  • 6,699
  • 2
  • 59
  • 74
lionscribe
  • 3,413
  • 1
  • 16
  • 21
4

I faced same issue !

Add android:clickable=true to your BottomSheet ! Should look like below !

<LinearLayout
    android:clickable="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/materialWhite"
    android:orientation="vertical"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
</LinearLayout>
gpl
  • 1,380
  • 2
  • 8
  • 24
Nisarg Jani
  • 415
  • 2
  • 12