Alix Blaine
Alix Blaine

Reputation: 821

AlertDialog does not display body text

I am using an AlertDialog() to display a dialog for about in my app. I tried, adding html text to my Strings resource. And I am accessing this below. But, for some unknown reason nothing is rendering out. Text is just some simple lorem ipsum.

AlertDialog(
            onDismissRequest = {
                tosVisible = false
            },
            icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
            title = {
                Text(text = "About this app")
            },
            text = {
                SelectionContainer{
                    TextView(context).setText(Html.fromHtml(stringResource(R.string.about_app), Html.FROM_HTML_MODE_COMPACT))
                }
            },
            confirmButton = {
                TextButton(
                    onClick = {
                        tosVisible = false
                    }
                ) {
                    Text("Confirm")
                }
            },
            dismissButton = {
                TextButton(
                    onClick = {
                        tosVisible = false
                    }
                ) {
                    Text("Dismiss")
                }
            }
        )

Output:

enter image description here

Upvotes: 1

Views: 204

Answers (2)

Ankit
Ankit

Reputation: 331

Check this answer, its work for me. just call the HtmlText function from the SelectionContainer.

https://stackoverflow.com/a/68397058/7248394

Upvotes: 1

Alix Blaine
Alix Blaine

Reputation: 821

Solution:

Text(modifier = Modifier.verticalScroll(rememberScrollState()),
     text = Html.fromHtml(stringResource(R.string.about_app), Html.FROM_HTML_MODE_COMPACT).toString())

Use Text under compose. Instead of TextView.

Upvotes: 1

Related Questions