Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I able to click "behind" the bottomsheet in Android?

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?

like image 343
user1865027 Avatar asked Sep 27 '16 21:09

user1865027


People also ask

How do I stop my android from dragging the bottom sheet?

set bottomSheet onClickListener to null. bottomSheet. setOnClickListener(null); this line disables all action about bottomSheet only and does not effect on inner view.

How can I dim the background when bottomSheet is displayed without using dialog?

Using the Interface - onSlide which as a parameter slideOffSet of type float , can be used to dim the background. The new offset of this bottom sheet within [-1,1] range. Offset increases as this bottom sheet is moving upward.

What does clickable do in Android?

clickable seems to be useful when you need a view to consume clicks so that they do not go to views beneath the top view. For example, I have a FrameLayout that I display over an underlying RelativeLayout at certain times. When the user would click on an underlying EditText the focus would shift to that EditText .


1 Answers

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.

like image 50
lionscribe Avatar answered Oct 09 '22 09:10

lionscribe