using styles <...">

How to fix a warning in android layout.xml: "missing contentDescription"

<ImageView style="@style/LoaderPrevNext.Next" />

using styles

<style name="LoaderPrevNext">
    <item name="android:layout_width">40dp</item>
    <item name="android:layout_height">80dp</item>
    <item name="android:layout_weight">0</item>
    <item name="android:scaleType">fitXY</item>
</style>

<style name="LoaderPrevNext.Next">
    <item name="android:src">@drawable/next_page</item>
    <item name="android:contentDescription">@string/img_desc_next_page</item>
</style>

annoying me with a warning [Accessibility] Missing contentDescription attribute on image.

It disappears if I move or copy the description of the content from the style to the ImageView tag, but since src is defined in the style, I would like to save them together.

Guess this is just an SDK bug, but some might get a workaround ...

Clarification: The ImageView in question has a content description defined in the style of LoaderPrevNext.Next. The warning is false. I'm not interested in ideas on how to establish a description of the content or how to crack it.

+5
source share
6 answers

Eclipse - > - > Android- > Lint Erroe Checking- > - > - > - > - > - >

+6

Android contentDescription

, , . contentDescription. , contentDescription - , , .

, contentDescription. , , .

Android lint - , IMO, contentDescription lint :

, , - , . lint tools:ignore="ContentDescription".

lint:

  • contentDescription XML android:contentDescription="Your description here." , . ,
  • tools:ignore="ContentDescription" .
+5

/ lint, strings.xml

string.xml:

<string name="empty"></string>

xml

<ImageView
    android:id="..."
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:contentDescription="@string/empty"/>
+1

< ImageView

android: id =...

android: layout_width =... ...

android: contentDescription = " . get from strings xml, "

/" >

0

.

- - , .

The same goes for the @string resource. Just do not put the description of the image in style. Leave @string. When necessary, change this line.

0
source

To disable the warning about the missing content description in the whole project, add it to yourbuild.gradle

android {
    lintOptions {
        disable 'ContentDescription'
    }
}
0
source

All Articles