16

[Accessibility] Missing contentDescription attribute on image

What does this error mean and how can I fix it?

<ImageButton
    android:id="@+id/callbannerbuttonpg1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="157dp"
    android:background="@null"
    android:src="@drawable/callbanner"
    android:visibility="invisible" />
user1091368
  • 359
  • 1
  • 4
  • 17

4 Answers4

20

Designing for Accessibility

"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."

And this is not error just a warning. Usage of this attribute is optional.

sianis
  • 598
  • 4
  • 13
  • Thanks worked like a charm, Yea i used it from a tutorial teaching how to use a regular button and an image button side by side and I guess they wanted to make the two distinct Thanks again. – user1091368 Jan 02 '12 at 14:03
  • 1
    The Designing for Accessibility link has gone 404, but the same content can be found here: http://developer.android.com/guide/topics/ui/accessibility/apps.html – Bill Carey Jul 02 '12 at 12:41
6

Add to the imageButton

android:contentDescription="@string/desc"
rds
  • 26,253
  • 19
  • 107
  • 134
3

Just add this:

android:contentDescription="@string/description"

then go to yours Strings.xml and add this:

<string name="description"> YOUR_DESCRIPTION_HERE </string>

as of your code:

<ImageButton
    android:id="@+id/callbannerbuttonpg1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="157dp"
    android:background="@null"
    android:src="@drawable/callbanner"
    android:visibility="invisible"
    android:contentDescription="@string/description" />
Cho Hee
  • 165
  • 1
  • 11
1

You can ignore such warnings as well by adding this in the imageButton tag :

tools:ignore="contentDescription"
Anonymous
  • 2,184
  • 15
  • 23