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?
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.
The content description attribute links a text description to a control, ImageView, or other focusable object that otherwise has no text content.
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.
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 :)
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.
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