Is there a way to custom checkbox to Read aloud with format : checkbox + [text] + [state of checkbox] that the screen reader, in android case the TalkBack, has to read the accessible elements ? CODE:
class CustomRadioButton : AppCompatRadioButton {
var talkBackString: CharSequence? = null
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
context,
attrs,
defStyle
) {
setupView()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
setupView()
}
constructor(context: Context) : super(context) {
setupView()
}
private fun setupView() {
accessibilityDelegate = MyAccessibilityDelegate()
}
inner class MyAccessibilityDelegate : AccessibilityDelegate() {
/**
* Override function onInitializeAccessibilityNodeInfo of AccessibilityDelegate
* @param host is [View]
* @param info is [AccessibilityNodeInfo]
*/
override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfo) {
super.onInitializeAccessibilityNodeInfo(host, info)
if (talkBackString.isNullOrEmpty() && host.contentDescription.isNullOrEmpty().not()) {
talkBackString = host.contentDescription
}
info.apply {
contentDescription = ""
hintText = talkBackString.toString()
error = ""
text = ""
}
}
}
}