136

I am getting warning as "[Accessibility] Missing contentDescription attribute on image" for imageview. while using android lint

What does that mean?

Janusz
  • 187,060
  • 113
  • 301
  • 369
MGK
  • 7,050
  • 6
  • 34
  • 41

11 Answers11

176

Resolved this warning by setting attribute android:contentDescription for my ImageView

android:contentDescription="@string/desc"

Android Lint support in ADT 16 throws this warning to ensure that image widgets provide a contentDescription.

This defines text that briefly describes content of the view. This property is used primarily for accessibility. Since some views do not have textual representation this attribute can be used for providing such.

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.

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
MGK
  • 7,050
  • 6
  • 34
  • 41
  • 4
    you can read more about it and test it by yourself by going to : http://android-developers.blogspot.com/2012/04/accessibility-are-you-serving-all-your.html and http://developer.android.com/guide/topics/ui/accessibility/apps.html#test – android developer May 15 '12 at 14:31
52

Disabling Lint warnings will easily get you into trouble later on. You're better off just specifying contentDescription for all of your ImageViews. If you don't need a description, then just use:

android:contentDescription="@null"
Dane White
  • 3,443
  • 18
  • 16
41

Another option is to suppress the warning individually:

xmlns:tools="http://schemas.android.com/tools"  (usually inserted automatically)
tools:ignore="contentDescription"

Example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    tools:ignore="contentDescription" >

       <ImageView
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:padding="5dp"
            android:src="@drawable/icon" />
Gunnar Bernstein
  • 6,074
  • 2
  • 45
  • 67
  • Incorrect - adding tools:ignore="contentDescription" into RelativeLayout led to compile error "Attribute is missing the Android namespace prefix" – G. Kh. Nov 18 '13 at 07:48
  • 3
    This is an eclipse issue. Just clean your project. And make sure: xmlns:tools="http://schemas.android.com/tools" is also included! – Gunnar Bernstein Nov 18 '13 at 15:09
25

I recommend you to add the contentDescription.

android:contentDescription="@string/contentDescriptionXxxx"

but, let's be realistic. Most people don't maintain literal for accessibility. Still, with little effort, you can implement something to help people with disability.

<string name="contentDescriptionUseless">deco</string>
<string name="contentDescriptionAction">button de action</string>
<string name="contentDescriptionContent">image with data</string>
<string name="contentDescriptionUserContent">image from an other user</string>

.

The most important thing the blind user will need to know is "Where is the button that I need to click to continue"

Use contentDescriptionAction for anything clickable.

use contentDescriptionContent for image with information (graph, textAsImage, ...)

use contentDescriptionUserContent for all user provided content.

use contentDescriptionUseless for all the rest.

Christ
  • 450
  • 6
  • 10
12

Since it is only a warning you can suppress it. Go to your XML's Graphical Layout and do this:

  1. Click on the right top corner red button

    enter image description here

  2. Select "Disable Issue Type" (for example)

    enter image description here

Sergio Carneiro
  • 3,726
  • 4
  • 35
  • 51
  • 5
    True, you _can_ suppress it, but you probably should follow the advice of the selected answer, for the sake of the users who rely on the accessibility tools Android provides. – Kyle Falconer Mar 25 '13 at 20:59
  • This is it!!! thats what i was looking for. This answer and @Gunnar Bernstein's answer got me. – IronBlossom Apr 23 '15 at 13:08
7

Go to Gradle file (module app), add below code block

android {
    ... 
    lintOptions {
        disable 'ContentDescription'
    }
    ...
}

No more warning! happy coding

GianhTran
  • 3,443
  • 2
  • 22
  • 42
7

If you want to suppress this warning in elegant way (because you are sure that accessibility is not needed for this particular ImageView), you can use special attribute:

android:importantForAccessibility="no"
2

ContentDescription needed for the Android accessibility. Particularly for the screen reader feature. If you don't support Android accessibility you can ignore it with setup Lint.

So just create lint.xml.

<?xml version="1.0" encoding="UTF-8"?>
<lint>

    <issue id="ContentDescription" severity="ignore" />

</lint>

And put it to the app folder.

enter image description here

Yvgen
  • 2,036
  • 2
  • 23
  • 27
2

For graphical elements that are purely decorative, set their respective android:contentDescription XML attributes to "@null".

If your app only supports devices running Android 4.1 (API level 16) or higher, you can instead set these elements' android:importantForAccessibility XML attributes to "no"

AnhSang
  • 150
  • 4
1

Non textual widgets need a content description in some ways to describe textually the image so that screens readers to be able to describe the user interface. You can ignore the property xmlns:tools="http://schemas.android.com/tools"
tools:ignore="contentDescription"
or define the property android:contentDescription="your description"

0

Since I need the ImageView to add an icon just for aesthetics I've added tools:ignore="ContentDescription" within each ImageView I had in my xml file.

I'm no longer getting any error messages

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
MikNik
  • 1