Friday, June 14, 2013

Missing contentDescription attribute on ImageView in XML - Android



I've the below ImageView in my XML file,

<ImageView  
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:id="@+id/myImgView"
            android:src="@drawable/something"/>

I get a warning saying that [Accessibility]Missing contentDescription attribute on image in Eclipse IDE. Since it is a warning we used to ignore it.. However to overcome this warning, all you need to add is the below piece of code in ImageView,

android:contentDescription="@string/description" (static or dynamic) 

This is helpful for people using alternative input methods because of their disability (like TalkBack, Tecla Access Shield etc)

You can read more about this here http://android-developers.blogspot.in/2012/04/accessibility-are-you-serving-all-your.html

No comments:

Post a Comment