vma*_*tyi 5 eclipse android android-layout
<ImageView style="@style/LoaderPrevNext.Next" />
Run Code Online (Sandbox Code Playgroud)
使用样式
<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>
Run Code Online (Sandbox Code Playgroud)
[Accessibility] Missing contentDescription attribute on image警告让我很生气.
如果我将contentDescription从样式移动或复制到ImageView标签,它就会消失,但由于src是在样式中定义的,我很乐意将它们保持在一起.
猜猜这只是一个SDK bug,但有些可能会有一个解决方法......
澄清:有问题的ImageView确实有一个内容描述,在LoaderPrevNext.Next样式中定义.警告是错误的.我对如何设置内容描述或如何将其破解为空的想法不感兴趣.
在Eclipse 窗口 - >首选项 - > Android-> Lint Erroe检查 - >右侧向下滚动直到可访问性 - >内容描述 - >严重性 - >选择忽略 - >应用 - >是
这个问题的两个现有答案在技术上都是正确的,但我相信有更好的方法.第一个答案建议关闭所有contentDescription警告.虽然这有效,contentDescription但是有一个原因,也许不应该全局关闭所有内容.
第二个答案显示了如何指定contentDescription.虽然这确实会使警告消失,但它并不适用于所有内容,并且在技术上不回答问题,尽管这是一种有效的解决方法.
lint的Android文档提供了最佳解决方案IMO,它提供contentDescription了一些内容,并抑制了其他内容的lint警告:
请注意,应用程序屏幕中的元素纯粹是装饰性的,不提供任何内容或启用用户操作,但不应具有可访问性内容描述.在这种情况下,只需使用
tools:ignore="ContentDescription"属性抑制lint警告.
因此,请实施以下解决方案以删除所有lint警告:
contentDescription在XML布局文件中定义android:contentDescription="Your description here."用于为用户提供有趣或有用信息的资源.和,tools:ignore="ContentDescription"到纯装饰性内容或图像.