Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is android:contentDescription="@string/desc" in ImageView's xml?

I added an imageView in GraphicalLayout but it looks different on my real device than on AVD.

I found that I need to add contentDescription in a layout .xml, but when I add: contentDescription="@string/desc"

there is an error:

"No resource found that matches the given name (at 'contentDescription' with value '@string/desc')"

What is this string "desc"? What should it looks like?

like image 880
foki Avatar asked Jul 21 '12 21:07

foki


People also ask

What does Android contentDescription do?

When using an ImageView , ImageButton , CheckBox , or other View that conveys information graphically, use an android:contentDescription attribute to provide a content label for that View . A content label sometimes depends on information only available at runtime, or the meaning of a View might change over time.

What is image content description?

The content description attribute links a text description to a control, ImageView, or other focusable object that otherwise has no text content.

Which of the following attributes should you add to ImageView and ImageButton elements to enable screen readers to describe the image?

Non-textual widgets like ImageViews and ImageButtons should use the contentDescription attribute to specify a textual description of the widget such that screen readers and other accessibility tools can adequately describe the user interface.


2 Answers

It's for the Accessibility Features of Android. The contentDescription is what get's read back to the (assumingly blind or hard-of-sight user) so they have an idea of what the picture is since they aren't able to view it.

As to answer your question, @iturki gives the start of it. You write the string to use for the description in strings.xml and give it a name of 'desc' or whatever your heart desires, then you set the value of contentDescription in the ImageView to @string/desc, either in the layout or programmatically. Like I said before, it's to help users with poor eyesight get a general idea of what the image is portraying :)

like image 124
starscream_disco_party Avatar answered Nov 15 '22 12:11

starscream_disco_party


That's for Accessibility (e.g., for a screen reader). You should define a string resource that describes the image, and reference it in contentDescription. See iturki's answer for how to do this.

like image 24
Sparky Avatar answered Nov 15 '22 12:11

Sparky