https://kotlinlang.org logo
a

Anthony Martin

10/01/2021, 3:32 PM
Does
AlertDialog
work with Compose
Preview
? I can't get it to work as it's saying "_The graphics preview in the layout editor may not be accurate - The preview does not support multiple windows._" Just trying to gain an understanding on what's doing wrong. Code:
Copy code
@Preview
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun SimpleComposeUIPreview() {
    AppTheme {
        DialogUI(
            message = "This is an example dialog message...",
            onPopBackStack = {}
        )
    }
}
Copy code
@Composable
private fun DialogUI(
    title: String = stringResource(R.string.title),
    message: String,
    positiveBtn: String = stringResource(R.string.pos),
    onPopBackStack: () -> Unit
) {
    AlertDialog(
        onDismissRequest = onPopBackStack,
        title = {
            Text(text = title)
        },
        text = {
            Text(text = message)
        },
        confirmButton = {
            TextButton(
                onClick = onPopBackStack,
            ) {
                Text(positiveBtn)
            }
        },
    )
}
Using version 1.1.0-alpha04 for Compose
🚫 1
🧵 3
a

Albert Chang

10/01/2021, 3:39 PM
a

Anthony Martin

10/01/2021, 3:45 PM
Thanks Albert
👍 1
7 Views