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

32,365

Solution 1

You need to add it in your string.xml file:

<string name="desc">your desc goes here</string>

Although I don't know why you NEED to add contentDescription to your imageView to solve the inconsistent look problem! I don't think this will solve it.

Solution 2

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 :)

Solution 3

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.

Share:
32,365
foki
Author by

foki

Updated on July 21, 2022

Comments

  • foki
    foki almost 2 years

    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?