Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I put in contentDescription attribute for decorative images such as field separator?

I gave an empty string. Lint still complains.

<ImageView style="@style/DetailFieldSeparator"/>

<style name="DetailFieldSeparator">
  <item name="android:src">@android:drawable/divider_horizontal_textfield</item>
  <item name="android:layout_width">match_parent</item>
  <item name="android:layout_height">wrap_content</item>
  <item name="android:scaleType">fitXY</item>
  <item name="android:paddingTop">5dp</item>
  <item name="android:paddingBottom">5dp</item>
</style>
like image 873
kimkunjj Avatar asked Jun 02 '12 18:06

kimkunjj


People also ask

How do you mark an image as a decorative in HTML?

To mark an image as decorative, all that is required is that you supply an empty ALT attribute. To do this, simply provide ALT text of “” to indicate an empty ALT attribute. This will signal a screen reader to skip over the image, taking it out of the reading flow.

Should images be marked as decorative?

Just because an image doesn't need alt text written, it does not mean you can publish the image and do nothing else. You still need to mark the image as "decorative" so screen readers know to skip the image when reading out page content.

What is a purely decorative image?

The Web Content Accessibility Guidelines 2.0 defines purely decorative images as: serving only an aesthetic purpose, providing no information, and having no functionality.

Which XML attribute should be used to make an image view accessible?

You can do this by adding the contentDescription attribute to your XML layout. It can also be done programmatically by calling the setContentDescription method in your Java file. Either method provides TalkBack with all the necessary information to describe the ImageView to users.


1 Answers

You can set the content description of a purely decorative image to "@null" to avoid Lint warnings and let the screen reader know to skip that image.

<ImageView
    style="@style/DetailFieldSeparator"
    android:contentDescription="@null" />
like image 64
alanv Avatar answered Oct 04 '22 07:10

alanv