Search code examples
androidandroid-jetpack-composelinkifymarkwon

Markwon linkify in a composable Text


In Android using jetpack-compose, is there currently a way to display a text containing links in a @Composable Text?

In legacy TextView, we used Markwon with linkify plugin. Markwon creates a Spanned object that we can set into the TextView's text.

Is there a way to proceed with the same with @Composable Text? Or do we have to use a legacy TextView embedded within a @Composable AndroidView?

Thank you


Solution

  • I think this library can help you: https://github.com/jeziellago/compose-markdown

    Add the repository to the project's build.gradle.

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' } // add this
        }
    }
    

    Then, add the dependency to the module's build.gradle

    implementation 'com.github.jeziellago:compose-markdown:0.2.0'
    

    and finally, you can use the library as follows:

    MarkdownText(
        markdown = "Click [here](http://www.google.com) or http://www.stackoverflow.com."
    )
    

    In this sample, both links are detected.