Android Lint 内容描述警告
我收到警告 imageview 的“[辅助功能] 图像上缺少 contentDescription 属性”。而使用 android lint
是什么意思?
I am getting warning as
"[Accessibility] Missing contentDescription attribute on image" for imageview. while using android lint
What does that mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
通过为我的 ImageView 设置属性
android:contentDescription
解决了此警告ADT 16 中的 Android Lint 支持会抛出此警告以确保图像小部件提供 contentDescription。
这定义了简要描述视图内容的文本。该属性主要用于辅助功能。由于某些视图没有文本表示,因此该属性可用于提供此类表示。
像 ImageViews 和 ImageButtons 这样的非文本小部件应该使用 contentDescription 属性来指定小部件的文本描述,以便屏幕阅读器和其他辅助工具可以充分描述用户界面。
Resolved this warning by setting attribute
android:contentDescription
for my ImageViewAndroid Lint support in ADT 16 throws this warning to ensure that image widgets provide a contentDescription.
This 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.
Non-textual widgets like ImageViews and ImageButtons should use the contentDescription attribute to specify a textual description of the widget such that screen readers and other accessibility tools can adequately describe the user interface.
禁用 Lint 警告很容易给您带来以后的麻烦。您最好只为所有 ImageView 指定 contentDescription。如果您不需要描述,则只需使用:
Disabling Lint warnings will easily get you into trouble later on. You're better off just specifying contentDescription for all of your ImageViews. If you don't need a description, then just use:
另一种选择是单独抑制警告:
示例:
Another option is to suppress the warning individually:
Example:
我建议您添加内容描述。
但是,让我们现实一点。大多数人不会为了可访问性而维护文字。
不过,只需付出很少的努力,您就可以实施一些措施来帮助残疾人。
。
盲人用户需要知道的最重要的事情是“我需要点击才能继续的按钮在哪里”
对任何可点击的内容使用 contentDescriptionAction。
对图像使用 contentDescriptionContent information (graph, textAsImage, ...)
使用 contentDescriptionUserContent 来表示所有用户提供的内容。
使用 contentDescriptionUseless 来处理其余的内容。
I recommend you to add the contentDescription.
but, let's be realistic. Most people don't maintain literal for accessibility.
Still, with little effort, you can implement something to help people with disability.
.
The most important thing the blind user will need to know is "Where is the button that I need to click to continue"
Use contentDescriptionAction for anything clickable.
use contentDescriptionContent for image with information (graph, textAsImage, ...)
use contentDescriptionUserContent for all user provided content.
use contentDescriptionUseless for all the rest.
由于这只是一个警告,您可以抑制它。转到 XML 的图形布局并执行以下操作:
单击右上角的红色按钮
选择“禁用问题类型”(例如)
Since it is only a warning you can suppress it. Go to your XML's Graphical Layout and do this:
Click on the right top corner red button
Select "Disable Issue Type" (for example)
转到
Gradle
文件(模块应用程序),添加以下代码块不再有警告!快乐编码
Go to
Gradle
file (module app), add below code blockNo more warning! happy coding
如果您想以优雅的方式抑制此警告(因为您确定此特定 ImageView 不需要可访问性),您可以使用特殊属性:
If you want to suppress this warning in elegant way (because you are sure that accessibility is not needed for this particular ImageView), you can use special attribute:
Android 可访问性所需的
ContentDescription
。特别是对于屏幕阅读器功能。
如果您不支持 Android 辅助功能,可以忽略它
通过设置Lint。
因此只需创建
lint.xml
即可。并将其放入
app
文件夹中。ContentDescription
needed for the Android accessibility.Particularly for the screen reader feature.
If you don't support Android accessibility you can ignore it
with setup Lint.
So just create
lint.xml
.And put it to the
app
folder.对于纯粹装饰性的图形元素,请将其各自的 android:contentDescription XML 属性设置为“@null”。
如果您的应用仅支持运行 Android 4.1(API 级别 16)或更高版本的设备,您可以将这些元素的 android:importantForAccessibility XML 属性设置为“no”
For graphical elements that are purely decorative, set their respective android:contentDescription XML attributes to "@null".
If your app only supports devices running Android 4.1 (API level 16) or higher, you can instead set these elements' android:importantForAccessibility XML attributes to "no"
非文本小部件需要以某种方式进行内容描述来以文本方式描述图像,以便屏幕阅读器能够描述用户界面。您可以忽略属性
xmlns:tools="http://schemas.android.com/tools"
或定义属性tools:ignore="contentDescription"
android:contentDescription="your description"
Non textual widgets need a content description in some ways to describe textually the image so that screens readers to be able to describe the user interface. You can ignore the property
xmlns:tools="http://schemas.android.com/tools"
or define the propertytools:ignore="contentDescription"
android:contentDescription="your description"
由于我需要 ImageView 添加一个图标只是为了美观,所以我在 xml 文件中的每个 ImageView 中添加了
tools:ignore="ContentDescription"
。我不再收到任何错误消息
Since I need the ImageView to add an icon just for aesthetics I've added
tools:ignore="ContentDescription"
within each ImageView I had in my xml file.I'm no longer getting any error messages