Accessibility value on Android
An accessibility value helps users of assistive technologies to understand the value of elements on the screen. A slider should indicate the currently selected value, and ideally also it's minimum and maximum value. The screen reader announces the value of elements as it reads the screen. It is important to assign correct values to elements to avoid misunderstanding.
Android has limited support to provide a dedicated accessibility value for assistive technologies. The AccessibilityNodeInfoCompat
object contains a couple of methods, such as the setChecked
method.
Unfortunately the desired value is often not available. If your desired value is not included, you can append it to the contentDescription
attribute.
ViewCompat.setAccessibilityDelegate(
element,
object : AccessibilityDelegateCompat() {
override fun onInitializeAccessibilityNodeInfo(
host: View,
info: AccessibilityNodeInfoCompat
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info.isChecked = true
}
}
)
element.contentDescription = "Name (Value)"