Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

contentDescription="@null" a bad idea?

Lint complains hey set a contentDescription. So to avoid creating a string I set it to null.

android:contentDescription="@null"

This seems to quiet down the complaints from lint. I'm a bit lost why I need to set a string reference to the contentDescription. What is the purpose of this? Why would I ever need this? and essentially setting it to null, is it a good idea?

like image 285
Jona Avatar asked Feb 08 '12 16:02

Jona


2 Answers

It's for accessibility for the blind. For accessibility, apps that utilize the contentDescription help blind people navigate by using Android's text-to-speech capabilities. So if someone selects an ImageButton via a trackpad or something, the TTS can speak the contentDescription so they can easily navigate the app. See this for more information.

To answer your question: it might silence the lint output, but it isn't doing anything necessarily bad or good.

like image 161
Brian Dupuis Avatar answered Sep 22 '22 08:09

Brian Dupuis


I know this question was asked awhile ago, but for the benefit of new readers who may run across this:

Brian is absolutely correct on what contentDescription is used for. However, there are times when it is not only appropriate but preferred to set it to @null. If an image is purely decorative and not clickable or content-related, you should set the contentDescription to @null. Otherwise, set it to something meaningful.

Remember anything set as a contentDescription is read out-loud by the device when a screen reader is used. Imagine in your mind a simple pop-up dialog. Now, mentally listen to these two different content descriptions for the same dialog:

  • "Information icon. Do you want to continue? Fancy horizontal rule. Button. Button."

    -vs-

  • "Do you want to continue? Submit. Cancel."

Content descriptions that aren't well thought-out end up sounding dumb. Items such as callout icons that simply repeat the text next to them or fancy borders that don't contribute to the meaning of the page should be suppressed with @null. Conversely everything clickable not only must have a description, it needs to have a meaningful description. If you try to set @null on something clickable, the device will speak "Button" instead. Changing the description to "Green Button" doesn't help. Don't make your users guess at what "Green Button" is!

If you're ever unsure, don't forget you can enable TalkBack on your phone. It's pre-installed on most devices or you can get it from the Play store. You will need a d-pad on older devices, or explore by touch on ICS and above.

like image 39
lisa Avatar answered Sep 21 '22 08:09

lisa