Cannot set dimAmount for BottomSheetDialogFragment in Android 13+

284 Views Asked by At

BottomSheetDialogFragment accepts only dipAmount of 1.0f (non-transparent black background), 0.99f and less are fully transparent background, this seems to be affecting only API 33+. Styles.xml attributes not working too. What should i do to set background dim to standart 0.32f?

I've tried setting attributes

<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.3</item>

Not worked. Then in code

requireDialog().window?.apply {
    addFlags(FLAG_DIM_BEHIND)

    val lp = attributes
    lp?.dimAmount = 0.32f
    attributes = lp

    setDimAmount(0.99f)
}

It's still absolutely transparent. But if i'll change to

setDimAmount(1.0f)

then BottomSheetDialogFragment's background will be absolutely black.

1

There are 1 best solutions below

0
Dragan Stojanov On

Possible, temporary solution:

    val dimmedBackgroundColor = Color.argb(82,0,0,0)//alpha = .32F 

    requireDialog().window?.apply {
        setDimAmount(0f)// remove dimmed back on older devices
        decorView.setBackgroundColor(dimmedBackgroundColor)
    }