Android accessibility IMPORTANT_FOR_ACCESSIBILITY_NO is not respected

13,278

Solution 1

When you set importantForAccessibility to no, you're only hiding the single view. You want to find the layout for the advertisement, and hide it and all of its descendants.

android:importantForAccessibility="noHideDescendants"

Should you want to do it programmatically, the constant you are looking for is:

IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS

Note: YOU ABSOLUTELY SHOULD NOT, do this. Advertisements are annoying for everyone. Separate is not equal. By hiding information, even annoying information, from VoiceOver you are breaking at least half a dozen WCag 2.0 criteria and making your application less accessible.

Solution 2

This is what I have done to achieve I have blocked descendant focus-ability which ad view gets by default as it get added to the view last. Wrapping the adview in a layout and adding property.

android:descendantFocusability="blocksDescendants"

My requirement was to assign focus to the first element in screen which I achieved using:

firstView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
firstView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);

I still agree to the point we should not change focus but this was only in case of ad. The ad is still focusable by touch.

Share:
13,278
SCP
Author by

SCP

Updated on June 17, 2022

Comments

  • SCP
    SCP about 2 years

    In my app I have ad on bottom, in accessibility (talkback) mode I don't want ads to be included. for this I have set this AdView and its parent to IMPORTANT_FOR_ACCESSIBILITY_NO and focusable = false, but it is not respected when app starts (Talkback enabled)the first item that gets focused is this ad.

    I request focus to desired item still ad is focused, how can I make this ad not focusable?

  • SCP
    SCP almost 9 years
    Hi @ChrisCM, I am working on android app to make it accessible, I am new to accessibility and facing issue in implementation, I have posted another question here : link hope you can help me on that Thanks
  • ataulm
    ataulm over 8 years
    Disagree with statement of not doing this (but I agree with the sentiment) - AdView is outside of your app's control and last I checked, it's not accessible using TalkBack (no content description). I think it's reasonable and proper to hide it.
  • ChrisCM
    ChrisCM over 8 years
    If there is no accessible content within an elemet where "descendants" have been hidden, the result will be the same as if they weren't hidden. If there are accessible elements within, then we have clearly hidden some content from the user. The only times we want to do this, is when this content is also hidden visually, however, the accessibility APIs still have access to it because you decided to hide it in a stupid way (EX: making it clear colored). That is the only exception I have found. I'm open to others, however, your example is certainly not one of them.