<ImageView style="@style/LoaderPrevNext.Next" />
using the styles
<style name="LoaderPrevNext">
<item name="android:layout_width">40dp</item>
<item name="android:layout_height">80dp</item>
<item name="android:layout_weight">0</item>
<item name="android:scaleType">fitXY</item>
</style>
<style name="LoaderPrevNext.Next">
<item name="android:src">@drawable/next_page</item>
<item name="android:contentDescription">@string/img_desc_next_page</item>
</style>
annoys me with the [Accessibility] Missing contentDescription attribute on image
warning.
It disappears if I move or copy the contentDescription from the style to the ImageView tag, but as the src is defined in the style, I'd love to keep them together.
Guess it's simply an SDK bug, but some might got a workaround...
Clarification: The ImageView in question do have a content-description, defined in the LoaderPrevNext.Next style. The warning is false. I'm not interested in ideas on how to set the content description, or how to hack them empty.
In Eclipse Window->Preferences->Android->Lint Erroe Checking->Right Side Scroll Down Until Accessibility->Content Description->Severity->Select Ignore->Apply->yes
Both of the existing answers to this question are technically correct, but I believe there is a better way. The first answer suggests turning off all contentDescription
warnings. While this works, contentDescription
is there for a reason, and perhaps should not be globally turned off for all content.
The second answer shows how to specify the contentDescription
. While this does make the warning go away, it is not appropriate for all content and technically does not answer the question, although it is a valid work-around.
The Android documentation for lint provides the best solution, IMO, which is a mixture of providing contentDescription
for some content, and suppressing the lint warning for other content:
Note that elements in application screens that are purely decorative and do not provide any content or enable a user action should not have accessibility content descriptions. In this case, just suppress the lint warning with a
tools:ignore="ContentDescription"
attribute.
Therefore, Implement the following solution to remove all of the lint warnings:
contentDescription
in your XML layout file with android:contentDescription="Your description here."
for resources that provide interesting or
useful information to the user. And,tools:ignore="ContentDescription"
to purely decorative content or
images.To disable missing content description warning in the whole project, add this to your build.gradle
android {
...
lintOptions {
disable 'ContentDescription'
}
}
If you do not wish to turn off / ignore the lint warnings you could define an empty string in strings.xml
string.xml:
<string name="empty"></string>
and then in your xml just set the value
<ImageView
android:id="..."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/empty"/>
contentDescription
tag is used for screen reading feature of android. you can add a string about what is your image is or you can just suppress/ignore this warning by adding the following tag.
tools:ignore="ContentDescription"
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