'Android accessibility identify heading
I have the latest version of Talkback and its announcing "My Top level Text Heading". Android native behaviour is adding "Heading" for my top level elements. I could not find a way to switch ON/OFF heading announcement. Is there an API to control its behaviour. In the previous version of Talkback versions it was not announcing "Heading" by itself.
Solution 1:[1]
You can enable or disable the "heading" accessibility property of any View on API 19+:
ViewCompat.setAccessibilityDelegate(headingView, new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
info.setHeading(true); // false to mark a view as not a heading
}
});
If you have minSdk 28, you can simply set this directly in your XML:
android:accessibilityHeading="false"
Solution 2:[2]
add a simple method on API 19+:
ViewCompat.setAccessibilityHeading(headingView, false);
Solution 3:[3]
If you're only supporting API level 23 and above, you can simply do the following.
textView.setAccessibilityDelegate(new View.AccessibilityDelegate() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
//blanked to prevent talkback from announcing class/type
info.setClassName("");
}
});
Solution 4:[4]
I solved this by passing heading as false in
AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain method.
// set the heading attribute to false so that heading is not announced in label
info.setCollectionItemInfo(
AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(glp.getSpanIndex(),
glp.getSpanSize(), spanGroupIndex, 1, false, false));
public static CollectionItemInfoCompat obtain(int rowIndex,
int rowSpan, int columnIndex, int columnSpan,
boolean heading, boolean selected)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | nbystndr |
| Solution 3 | CodeDaily |
| Solution 4 | moxi |
