Contains the methods to be used by Text

Summary

Public functions

LinkAnnotation.Clickable
@Composable
Clickable(
    tag: String,
    linkStyle: SpanStyle?,
    linkFocusedStyle: SpanStyle?,
    linkHoveredStyle: SpanStyle?,
    linkInteractionListener: LinkInteractionListener?
)

Constructs a LinkAnnotation.Clickable and applies default styling from the MaterialTheme

Cmn
LinkAnnotation.Url
@Composable
Url(
    url: String,
    linkStyle: SpanStyle?,
    linkFocusedStyle: SpanStyle?,
    linkHoveredStyle: SpanStyle?,
    linkInteractionListener: LinkInteractionListener?
)

Constructs a LinkAnnotation.Url and applies default styling from the MaterialTheme

Cmn
AnnotatedString
@Composable
fromHtml(
    htmlString: String,
    linkStyle: SpanStyle?,
    linkFocusedStyle: SpanStyle?,
    linkHoveredStyle: SpanStyle?,
    linkInteractionListener: LinkInteractionListener?
)

Converts a string with HTML tags into AnnotatedString.

Cmn

Public functions

Clickable

@Composable
fun Clickable(
    tag: String,
    linkStyle: SpanStyle? = SpanStyle(color = MaterialTheme.colorScheme.primary),
    linkFocusedStyle: SpanStyle? = null,
    linkHoveredStyle: SpanStyle? = null,
    linkInteractionListener: LinkInteractionListener?
): LinkAnnotation.Clickable

Constructs a LinkAnnotation.Clickable and applies default styling from the MaterialTheme

Url

@Composable
fun Url(
    url: String,
    linkStyle: SpanStyle? = SpanStyle(color = MaterialTheme.colorScheme.primary),
    linkFocusedStyle: SpanStyle? = null,
    linkHoveredStyle: SpanStyle? = null,
    linkInteractionListener: LinkInteractionListener? = null
): LinkAnnotation.Url

Constructs a LinkAnnotation.Url and applies default styling from the MaterialTheme

import androidx.compose.material3.Text
import androidx.compose.material3.TextDefaults
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withLink

Text(buildAnnotatedString {
    append("Build better apps faster with ")
    withLink(TextDefaults.Url(url = "https://developer.android.com/jetpack/compose")) {
        append("Jetpack Compose")
    }
})

fromHtml

@Composable
fun fromHtml(
    htmlString: String,
    linkStyle: SpanStyle? = SpanStyle(color = MaterialTheme.colorScheme.primary),
    linkFocusedStyle: SpanStyle? = null,
    linkHoveredStyle: SpanStyle? = null,
    linkInteractionListener: LinkInteractionListener? = null
): AnnotatedString

Converts a string with HTML tags into AnnotatedString. Applies default styling from the MaterialTheme to links present in the htmlString.

Check androidx.compose.ui.text.AnnotatedString.Companion.fromHtml for more details on supported tags and usage.

Parameters
htmlString: String

HTML-tagged string to be parsed to construct AnnotatedString

linkStyle: SpanStyle? = SpanStyle(color = MaterialTheme.colorScheme.primary)

style to be applied to links present in the string

linkFocusedStyle: SpanStyle? = null

style to be applied to links present in the string when they are focused

linkHoveredStyle: SpanStyle? = null

style to be applied to links present in the string when they are hovered

linkInteractionListener: LinkInteractionListener? = null

a listener that will be attached to links that are present in the string and triggered when user clicks on those links. When set to null, which is a default, the system will try to open the corresponding links with the androidx.compose.ui.platform.UriHandler composition local

See also
fromHtml