android i`importantForA11y=false` vs. `setConentDescription=@null` vs. `focusable=false`

202 Views Asked by At

I can see importantForA11y is for minSdk=6+

But why would one have to use it, if they can just use setConentDescription=@null?

What is the difference between importantForA11y=false vs. setConentDescription=@null vs. focusable=false

1

There are 1 best solutions below

0
On

ImportantForAccessibility=false is used to hide any element from the accessibility tree, including buttons, content etc.

contentDescription=null is only useful for things like images (there may be other items I can't think of) that you want to hide as otherwise the Accessibility Tree will do it's best to find a suitable name for an item.

A prime example would be an ImageButton - if you use contentDescription=null then it will announce 'button' and the destination / button text. If you use ImportantForAccessibility=false it would hide that item completely from the accessibility tree.

The best analogy I can come up with (if you are familiar with Web Standards) is that contentDescription is like an alt attribute or aria-labelledby attribute and ImportantForAccessibility=false is similar to aria-hidden="true".

With regards to focusable=false, this should be used for things like ImageViews, it should always be used in conjunction with importantForAccessibility=false (or importantForAccessibility="no") to ensure an item that is purely decorative is completely removed from the accessibility tree.

There are probably some edge cases I can't think of so above all, test it with TalkBack or a similar screen reader.