This question may seem a little bit odd, but let me explain my problem.
I have a BottomSheetDialogFragment
with rounded top corners. When I fully expand my dialog those corners will be filled automatically. I want the height to be more or less fixed, so isFitToContents
is set to false.
Preferably I want my expanded state to have a slight margin to the top and still transparent corners, so the user is able to see a bit of the underlying layout. STATE_HALF_EXPANDED
with a halfExpandedRatio
of something like 0.95 is pretty much it.
But then the user is still able to switch to STATE_EXPANDED
with a swipe up, which is weird, because there is almost no difference in height between both states, so this seems unnecessary.
Is there a way to make STATE_HALF_EXPANDED
the maximum (disable STATE_EXPANDED
) or, as an alternative, can I make STATE_EXPANDED
behave as described and skip STATE_HALF_EXPANDED
instead?
It seems like a really small thing, but I didn't find a way to achieve this behavior yet.
(I'm using XML layouts if this is relevant.)
This is what I currently apply to the dialog in the onShowListener
:
isFitToContents = false
halfExpandedRatio = 0.95f
state = BottomSheetBehavior.STATE_HALF_EXPANDED
skipCollapsed = true
And in onViewCreated
I ensure the parent layout's height is MATCH_PARENT
, so the area below my inflated layout is not transparent:
val parentLayout = dialog?.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
parentLayout?.layoutParams?.height = ViewGroup.LayoutParams.MATCH_PARENT