BottomSheetDialog fills the background instead of dimming it

89 views Asked by At

enter image description here

As you can see the part on top of the dialog is entirely white and not dimmed as it should be by default

I tried messing with styles, making windowBackground and Background transparent also doing it programatically. I tried making it in a new clean project and it worked correctly without any modifications whatsoever, as far as i can tell it should be default behavior and it's not the emulator/device problem as it worked with the new project. Here's the code

itemNotification.setOnClickListener {
    notificationsBottomSheetDialog.show()
}
notificationsBottomSheetBinding = FragmentNotificationsBottomSheetBinding.inflate(layoutInflater)
notificationsBottomSheetDialog = BottomSheetDialog(requireContext(), style.CustomBottomSheetDialog)
notificationsBottomSheetDialog.setCanceledOnTouchOutside(false)
notificationsBottomSheetDialog.setContentView(notificationsBottomSheetBinding.root)

Bottom sheet layout.xml

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/bSheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingHorizontal="@dimen/core_padding_16"
    android:paddingTop="@dimen/core_vertical_margin_16"
    android:paddingBottom="@dimen/core_vertical_margin">
<other stuff but not empty>

All the styles

CustomBottomSheetDialog:
    parent = ThemeOverlay.MaterialComponents.BottomSheetDialog
    bottomSheetStyle = @style/CustomBottomSheet => @style/CustomBottomSheet

CustomBottomSheet:
    parent = Widget.MaterialComponents.BottomSheet
    shapeAppearanceOverlay = @style/CustomShapeAppearanceBottomSheetDialog

CustomShapeAppearanceBottomSheetDialog:
    cornerFamily = rounded
    cornerSizeTopRight = 16dp
    cornerSizeTopLeft = 16dp
    cornerSizeBottomRight = 0dp
    cornerSizeBottomLeft = 0dp
    android:windowSoftInputMode = adjustResize

It also doesn't have rounded corners on top without the style even though in the new app it did, initializing it without the style still does the same white background

The dialog is called from a fragment if that makes a difference

2

There are 2 answers

1
Anirudh Goud On

You could try by setting within onCreate a style this way

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setStyle(DialogFragment.STYLE_NORMAL,R.style.SaveBottomSheetDialogStyle) }

Then provide a style in styles.xml

<style name="SaveBottomSheetDialogStyle" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/ModalStyle.Transparent</item>
    <item name="colorAccent">@color/red</item>
</style>

The XML can be as you desire with a background.xml file added to you view

3
C.F.G On

Try adding this:

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

to your Bottomsheet root layout.