Jetpack Compose Alertdialog Increase Spacing Between Title and Content

December 15, 2021

Padding in text doesn’t add to the spacing, so I discard the use of title and load a custom title in text instead.

AlertDialog(
    modifier = Modifier.fillMaxWidth(),
    onDismissRequest = {
        onDismiss()
    },
    /*
    // discard title usage
    title = {
       if (!title.isNullOrEmpty()) {
           Text(title)
       }
    },
     */
    text = {
        Column (
            modifier = Modifier
                .fillMaxWidth()
                .padding(8.dp),
            // horizontalAlignment = Alignment.CenterHorizontally
        ) {

            // create custom title
            if (!title.isNullOrEmpty()) {
                Text(title,
                    modifier = Modifier.padding(vertical = 8.dp),
                    style = MaterialTheme.typography.subtitle1)
            }


            ProgressBar(modifier = Modifier
                .height(16.dp)
                .fillMaxWidth(), progress = progress)
        }
    },
    buttons = { }
)

NOTE: Stefano mentioned this problem is solved in Material 3, but I have yet to try it.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.