Problem with custom dialog show in jetpack compose. Not correct background

485 Views Asked by At

I'm created custom dialog from common class in ini

init {
    activity.setContent {
        CustomDialog(viewModel)
    }
}

@Composable
fun CustomDialog(viewModel: ViewModel){
Dialog(
        onDismissRequest = {  },
        properties = DialogProperties(dismissOnBackPress = true, dismissOnClickOutside = true)
    ) {
}
}

But under dialog background is an empty activity, but must be a preference activity.

Not correct composable: composable

correct dialog via XML:

xml

I tried, but didn't help

                        Surface(modifier = Modifier.background(Color.Transparent)) {
                            CustomDialog(viewModel)
                        }
    ```
2

There are 2 best solutions below

2
Halifax On

Exampe:

Dialog(onDismissRequest = { onDismissRequest() }, properties = DialogProperties()) {
        Column(
            modifier = Modifier
                .wrapContentSize()
                .background(
                    color = MaterialTheme.colors.surface,
                    shape = RoundedCornerShape(size = 16.dp)
                ).clip(shape = RoundedCornerShape(size = 16.dp))
        ) {
    //.....

   }
}
0
Slava On

Found solution:

dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog?.window?.setDimAmount(0.0f)