Clickable links

Background

People who rely on an accessibility service to use mobile devices benefit from clearly displayed links. For example, someone who is blind and uses the TalkBack screen reader can easily access links from the local context menu.

Android offers developers several different ways to display text that is styled and behaves as a hyperlink. Some approaches support accessibility services more reliably than others.

Implementation

Use URLSpan or the convenience class Linkify to display hyperlinks in an app's user interface. An accessibility service is more likely to detect and activate these links on behalf of the user.

If you use URLSpan, use an absolute URL (https://android.com/robots.txt), not a relative URL (/robots.txt).

It may be difficult for some accessibility services to detect and activate ClickableSpan reliably. Instead, consider using a URLSpan with a matching IntentFilter to handle the click action, as an accessibility service may activate these hyperlinks via an intent broadcast.

Note that this is no longer applicable for Android 8.0 (API level 26) and later.

Design

When using TalkBack to speak text containing a hyperlink, a well implemented user interface produces an auditory icon as the hyperlinked text is spoken, and the linked text appears in the "Links" sub-menu of TalkBack's local context menu.

Testing

To manually verify if an app is displaying hyperlinked text to accessibility services:

  1. Turn on TalkBack.
  2. Open the app.
  3. Move accessibility focus to the item containing the hyperlink.
  4. As the hyperlinked area of text within that item is spoken, listen for a chime to indicate hyperlinked text.
  5. While the item containing hyperlinked text has accessibility focus, open TalkBack's local context menu.
  6. Check if the hyperlinked text appears in the "Links" sub-menu.

Android's automated testing tools can detect incorrectly implemented hyperlinks. Consider using Accessibility Scanner for Android for manual testing of your app on-device. For automated tests, turn on accessibility checking in Espresso and Robolectric.