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.
Asked
Active
Viewed 1.2k times
10
-
What kind of control are you using to get it to read this? I have the opposite problem, I WANT it to read heading and have been having to put it in manually on the content description. – Mr_E Mar 14 '17 at 14:29
-
@Mr_E Were you able to solve your issue? – Chris Leyva Nov 20 '18 at 18:35
4 Answers
8
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"
-
1in which API this method added? `AccessibilityNodeInfoCompat#setHeading(boolean)` – MilapTank Feb 12 '19 at 11:46
-
2Hi @Adam S , this does not appear to work for me. The textview is not announcing that it is a heading when you do `setHeading(true)`. – h_k Nov 04 '19 at 15:17
-
Yup, it's added in 28 https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#setHeading(boolean) – Kornilov Ruslan Oct 09 '20 at 15:54
5
Here is a simpler method:
ViewCompat.setAccessibilityHeading(headingView, false);

nbystndr
- 521
- 1
- 6
- 15
1
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("");
}
});

CodeDaily
- 756
- 4
- 17
1
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)