Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Accessibility - unable to announce TextViews as a Header or link

I have some TextViews that I would like to announce as a header or a link in Talkback mode. Currently, it just announces the text inside the TextView, but I would like it to say "Heading" afterwards, or "link" depending on the TextView. For example, I would like Talkback mode to announce "Log in - heading" rather than just "Log in".

What I have tried so far is adding this in my Activity's onCreate():

ViewCompat.setAccessibilityDelegate(v, new AccessibilityDelegateCompat() {
        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setHeading(true);
        }
    });

In Talkback mode, there is no change - it still just announces "log in".

What I notice is that this method, onInitializeAccessibilityNodeInfo, is being called multiple times. When I step through in debugger, every time this method is triggered it shows that isHeading() is false, then set to true.

Am I using this method incorrectly? Why is it called many times? Why is info.setHeading(true) basically ignored?

How would I accomplish something similar, but with Talkback mode announcing "Label - Link" instead of header?

like image 726
h_k Avatar asked Nov 04 '19 16:11

h_k


1 Answers

Try this:

ViewCompat.setAccessibilityDelegate(v, new AccessibilityDelegateCompat() {
    @Override
    public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
        super.onInitializeAccessibilityNodeInfo(host, info);
        info.setRoleDesccription("heading");
    }
});
like image 88
JavaGhost Avatar answered Oct 22 '22 21:10

JavaGhost