Accessibility label - Android
On Android, you can use the contentDescription
attribute to set an accessibility label.
You can also pass any kind of Span
for greater control over pronunciation. For example, you can set a language by using LocaleSpan
.
If another element is used to display the label, you can link the label by using the labelFor
attribute.
// Set accessibility label
element.contentDescription = "Appt"
// Set accessibility label in Dutch language
val locale = Locale.forLanguageTag("nl-NL")
val localeSpan = LocaleSpan(locale)
val string = SpannableString("Appt")
string.setSpan(localeSpan, 0, string.length, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
element.contentDescription = localeSpan
// Link visual label to field
textView.setLabelFor(R.id.editText)