Success Criterion 2.4.4 - Level A
Link Purpose (In Context)
Ensure the purpose of each link is clear. Users can request a list of links. The link and its surrounding text should indicate where you will navigate to. Clear links are useful for everyone and especially for users of assistive technologies users.
Impact
Assistive technologies can show an overview of all links on the screen. The purpose of each link should be clear immediately.
Check
“Is the purpose of each link clear?“
This can be tested without assistive technologies.
Solution
Mark links
On Android, links should be embedded inside an URLSpan
.
To create text links, you can show the span
in using the setText
method of TextView
. To support assistive technologies on lower version of Android, you need to call the ViewCompat.enableAccessibleClickableSpanSupport()
method.
The helper method ViewCompat.addLinks()
is also useful to automatically create accessible links.
Warning: you have to remove the android:autoLink
attribute from your XML to make your URLSpan
's clickable.
val textView = TextView(this)
val url = "https://appt.org"
val link = "Appt"
val spannableString = SpannableString("Learn more about $link")
val index = spannableString.indexOf(link)
spannableString.setSpan(URLSpan(url), index, index + link.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
textView.text = spannableString
textView.movementMethod = LinkMovementMethod.getInstance()
ViewCompat.enableAccessibleClickableSpanSupport(textView)