如何将超链接添加到 Text 组件文本的某些部分?
随着buildAnnotatedString我可以设置链接部分蓝色并带有下划线,如下面的图像,但我怎么也可以把这一节变成链接?
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
)
Run Code Online (Sandbox Code Playgroud)
我也可以,Spanned但有什么方法可以使用它Text吗?
val str: Spanned = HtmlCompat.fromHtml(
"<a href=\"http://www.github.com\">Github</a>", HtmlCompat.FROM_HTML_MODE_LEGACY
)
Run Code Online (Sandbox Code Playgroud) android android-jetpack-compose android-jetpack-compose-text