Links¶
The Rich Text Editor provides comprehensive support for hyperlinks, allowing you to: - Add links to new or existing text - Update link URLs - Remove links - Customize link appearance - Handle link clicks
Adding Links¶
New Text with Link¶
To add a new text with a link, use the addLink
method:
// Add link after selection
richTextState.addLink(
text = "Compose Rich Editor",
url = "https://github.com/MohamedRejeb/Compose-Rich-Editor"
)
Converting Text to Link¶
To convert selected text into a link, use the addLinkToSelection
method:
Managing Links¶
Updating Links¶
To update an existing link's URL:
Removing Links¶
To remove a link while keeping the text:
Link Information¶
Checking Link Status¶
To check if the current selection is a link:
Getting Link Details¶
To get the current link's text and URL:
// Get link text and URL
val linkText = richTextState.selectedLinkText
val linkUrl = richTextState.selectedLinkUrl
Customizing Links¶
Link Appearance¶
You can customize how links appear in the editor:
richTextState.config.linkColor = Color.Blue
richTextState.config.linkTextDecoration = TextDecoration.Underline
Handling Link Clicks¶
By default, links are opened by your platform's UriHandler
. To customize link handling:
val myUriHandler = remember {
object : UriHandler {
override fun openUri(uri: String) {
// Custom link handling logic
// For example: open in specific browser, validate URL, etc.
}
}
}
CompositionLocalProvider(LocalUriHandler provides myUriHandler) {
RichText(
state = richTextState,
modifier = Modifier.fillMaxWidth()
)
}