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?
Android defines android:importantForAccessibility as: Describes whether or not this view is important for accessibility. If it is important, the view fires accessibility events and is reported to accessibility services that query the screen.
An Accessibility Service assists users with disabilities in using Android devices and apps. It is a long-running privileged service that helps users process information on the screen and lets them to interact meaningfully with a device.
TalkBack. TalkBack is Android's built-in screen reader. When TalkBack is on, users can interact with their Android device without seeing the screen. Users with visual impairments may rely on TalkBack to use your app.
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.
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.
Straight from docs
android:importantForAccessibility Describes whether or not this view is important for accessibility. If it is important, the view fires accessibility events and is reported to accessibility services that query the screen. Note: While not recommended, an accessibility service may decide to ignore this attribute and operate on all views in the view tree.
though that note makes no sense by itself: what is not recommended and by or to whom? but probably means that this feature may not be taken into account by actual accessibility services (Talkback etc). It does not work in API23 but does work in 26 on webviews, from my experience.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With