TextLink

TextLink
TextLink

TextLink is not a view, it is an extension function over TextView which allows you to set links inside a TextView.

TextView.setTextLinkList(textLinkList: List<TextLink>, goToWebUrl: (String) -> Unit)

Usage

To set a link in a TextView with text you need to:

  1. Define your string resource in your XML file with an annotation tag surrounding the link text.
    <string name="text_with_links">This is an example <annotation type="myLinkValue">with this link</annotation>.</string>
  2. Create a list of TextLink which has the annotation type value and the link which should open.
    val textLinkList = listOf(TextLink("myLinkValue", "https://www.example.com"))
  3. Set the string to the TextView, in code or layout.
  4. Call setTextLinkList over the TextView with the list of TextLink and a function reference to navigate to a WebView.
    textView.setTextLinkList(it.textLinkList, navigator::goToWeb)