[android] 'Missing contentDescription attribute on image' in XML

I get an warning about [Accessibility]Missing contentDescription attribute on image in eclipse. This warning show at line 5 (declare ImageView) in XML code below.

This not make any error when build and run my application. But I really want to know why i get this warning.

This is my XML file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/contact_entry_image"
        android:src="@drawable/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/contact_entry_text"
        android:text=""
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        />

</LinearLayout>

Please help me regarding this and thanks for your reading.

The answer is


If you don't care at all do this:

    android:contentDescription="@null"

Although I would advise the accepted solutions, this is a hack :D


Add

tools:ignore="ContentDescription"

to your image. Make sure you have xmlns:tools="http://schemas.android.com/tools" . in your root layout.


It is giving you the warning because the image description is not defined.

We can resolve this warning by adding this code below in Strings.xml and activity_main.xml

Add this line below in Strings.xml

<string name="imgDescription">Background Picture</string>
you image will be like that:
<ImageView
        android:id="@+id/imageView2"
        android:lay`enter code hereout_width="0dp"
        android:layout_height="wrap_content"
        android:contentDescription="@string/imgDescription"
        app:layout_editor_absoluteX="0dp"
        app:layout_editor_absoluteY="0dp"
        app:srcCompat="@drawable/background1"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp" />

Also add this line in activity_main.xml

android:contentDescription="@string/imgDescription"

Strings.xml

<resources>
    <string name="app_name">Saini_Browser</string>
    <string name="SainiBrowser">textView2</string>
    <string name="imgDescription">BackGround Picture</string>
</resources>

Updated:

As pointed out in the comments, setting the description to null indicates that the image is purely decorative and is understood as that by screen readers like TalkBack.

Old answer, I no longer support this answer:

For all the people looking how to avoid the warning:

I don't think android:contentDescription="@null" is the best solution.

I'm using tools:ignore="ContentDescription" that is what is meant to be.

Make sure you include xmlns:tools="http://schemas.android.com/tools" in your root layout.


This warning tries to improve accessibility of your application.

To disable missing content description warning in the whole project, you can add this to your application module build.gradle

android {

    ...

    lintOptions {
        disable 'ContentDescription'
    }
}

Going forward, for graphical elements that are purely decorative, the best solution is to use:

android:importantForAccessibility="no"

This makes sense if your min SDK version is at least 16, since devices running lower versions will ignore this attribute.

If you're stuck supporting older versions, you should use (like others pointed out already):

android:contentDescription="@null"

Source: https://developer.android.com/guide/topics/ui/accessibility/apps#label-elements


The warning is indeed annoying and in many (most!) cases no contentDescription is necessary for various decorative ImageViews. The most radical way to solve the problem is just to tell the Lint to ignore this check. In Eclipse, go to "Android/Lint Error Checking" in Preferences, find "contentDescription" (it is in the "Accessibility" group) and change "Severity:" to Ignore.


Add android:contentDescription="@string/description" (static or dynamic) to your ImageView. Please do not ignore nor filter the message, because it is helpfull for people using alternative input methods because of their disability (Like TalkBack, Tecla Access Shield etc etc).


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to warnings

numpy division with RuntimeWarning: invalid value encountered in double_scalars libpng warning: iCCP: known incorrect sRGB profile How to use _CRT_SECURE_NO_WARNINGS C pointers and arrays: [Warning] assignment makes pointer from integer without a cast Server configuration by allow_url_fopen=0 in IntelliJ IDEA shows errors when using Spring's @Autowired annotation Warning :-Presenting view controllers on detached view controllers is discouraged Data truncated for column? Warning message: In `...` : invalid factor level, NA generated How to suppress warnings globally in an R Script

Examples related to accessibility

Speech input for visually impaired users without the need to tap the screen 'Missing contentDescription attribute on image' in XML input type="submit" Vs button tag are they interchangeable? What would be the best method to code heading/title for <ul> or <ol>, Like we have <caption> in <table>? Get a Windows Forms control by name in C# HTML img tag: title attribute vs. alt attribute? How to find good looking font color if background color is known? How can you program if you're blind?

Examples related to android-imageview

How to set a ripple effect on textview or imageview on Android? Placing a textview on top of imageview in android How to create a circular ImageView in Android? How to download and save an image in Android Android ImageView Fixing Image Size "Bitmap too large to be uploaded into a texture" Android Camera : data intent returns null 'Missing contentDescription attribute on image' in XML Android ImageView Zoom-in and Zoom-Out findViewById in Fragment