You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an annotated string built to highlight clickable text, but I'm wondering how I can signify that text is clickable through the cursor.
I can add the modifier to the ClickableText component, however that would make the entire text seem as though it's clickable, which is counterintuitive.
Code Example
val spanStyle =SpanStyle(
color =MaterialTheme.colorScheme.primary,
fontWeight =FontWeight.Bold,
textDecoration =Underline
)
val disclaimerString = buildAnnotatedString {
append("By logging in, you agree to our ")
pushStringAnnotation(tag ="tandc", annotation ="https://google.com")
withStyle(spanStyle) { append("Terms & Conditions") }
pop()
append(" and ")
pushStringAnnotation(tag ="policy", annotation ="https://google.com")
withStyle(spanStyle) { append("Privacy Policy") }
pop()
append(".")
}
ClickableText(
text = disclaimerString,
modifier =Modifier.padding(all =18.dp),
style =MaterialTheme.typography.bodyMedium.copy(color =MaterialTheme.colorScheme.onSurface),
onClick = { offset ->listOf("tandc", "policy").forEach { tag ->
disclaimerString.getStringAnnotations(tag, start = offset, end = offset)
.firstOrNull()
?.let { uriHandler.openUri(it.item) }
}
}
)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have an annotated string built to highlight clickable text, but I'm wondering how I can signify that text is clickable through the cursor.
I can add the modifier to the ClickableText component, however that would make the entire text seem as though it's clickable, which is counterintuitive.
Code Example
Beta Was this translation helpful? Give feedback.
All reactions