How can i add hyperlink to some section of the text of Text component?
With buildAnnotatedString
i can set link section blue and underlined as in image below, but how can i also turn that section into link?
val annotatedLinkString = buildAnnotatedString {
val str = "Click this link to go to web site"
val startIndex = str.indexOf("link")
val endIndex = startIndex + 4
append(str)
addStyle(
style = SpanStyle(
color = Color(0xff64B5F6),
textDecoration = TextDecoration.Underline
), start = startIndex, end = endIndex
)
}
Text(
modifier = modifier
.padding(16.dp)
.fillMaxWidth(),
text = annotatedLinkString
)
I can also get Spanned
but is there any way to use it with Text
?
val str: Spanned = HtmlCompat.fromHtml(
"<a href="http://www.github.com">Github</a>", HtmlCompat.FROM_HTML_MODE_LEGACY
)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…