LinkAnnotation.Clickable


An annotation that contains a clickable marked with tag. When clicking on the text to which this annotation is attached, the app will trigger a linkInteractionListener listener.

See also
LinkAnnotation

Summary

Public constructors

Clickable(
    tag: String,
    styles: TextLinkStyles?,
    linkInteractionListener: LinkInteractionListener?
)
Cmn

Public functions

LinkAnnotation.Clickable
copy(
    tag: String,
    styles: TextLinkStyles?,
    linkInteractionListener: LinkInteractionListener?
)

Returns a copy of this Clickable, optionally overriding some of the values.

Cmn
open operator Boolean
equals(other: Any?)
Cmn
open Int
Cmn
open String
Cmn

Public properties

open LinkInteractionListener?

Interaction listener triggered when user interacts with this link.

Cmn
open TextLinkStyles?

Style configuration for this link in different states.

Cmn
String
Cmn

Public constructors

Clickable

Clickable(
    tag: String,
    styles: TextLinkStyles? = null,
    linkInteractionListener: LinkInteractionListener?
)

Public functions

copy

fun copy(
    tag: String = this.tag,
    styles: TextLinkStyles? = this.styles,
    linkInteractionListener: LinkInteractionListener? = this.linkInteractionListener
): LinkAnnotation.Clickable

Returns a copy of this Clickable, optionally overriding some of the values.

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

linkInteractionListener

open val linkInteractionListenerLinkInteractionListener?

Interaction listener triggered when user interacts with this link.

import androidx.compose.foundation.text.BasicText
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.LinkAnnotation
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withLink
import androidx.compose.ui.unit.sp

// Display a link in the text and log metrics whenever user clicks on it. In that case we handle
// the link using openUri method of the LocalUriHandler
val uriHandler = LocalUriHandler.current
BasicText(
    buildAnnotatedString {
        append("Build better apps faster with ")
        val link =
            LinkAnnotation.Url(
                "https://developer.android.com/jetpack/compose",
                TextLinkStyles(SpanStyle(color = Color.Blue))
            ) {
                val url = (it as LinkAnnotation.Url).url
                // log some metrics
                uriHandler.openUri(url)
            }
        withLink(link) { append("Jetpack Compose") }
    }
)

styles

open val stylesTextLinkStyles?

Style configuration for this link in different states.

import androidx.compose.foundation.text.BasicText
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.LinkAnnotation
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withLink
import androidx.compose.ui.unit.sp

// Display a link in the text that gets an underline when hovered
BasicText(
    buildAnnotatedString {
        append("Build better apps faster with ")
        val link =
            LinkAnnotation.Url(
                "https://developer.android.com/jetpack/compose",
                TextLinkStyles(
                    style = SpanStyle(color = Color.Blue),
                    hoveredStyle = SpanStyle(textDecoration = TextDecoration.Underline)
                )
            )
        withLink(link) { append("Jetpack Compose") }
    }
)

tag

val tagString