我得到一个关于[可访问性]在eclipse图像上缺少contentDescription属性的警告。这个警告显示在下面XML代码中的第5行(声明ImageView)。

这不会使任何错误时,构建和运行我的应用程序。但我真的想知道为什么我得到这个警告。

这是我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/contact_entry_image"
        android:src="@drawable/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/contact_entry_text"
        android:text=""
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        />

</LinearLayout>

请帮助我,感谢您的阅读。


当前回答

按照这个链接的解决方案:Android Lint内容描述警告

Resolved this warning by setting attribute android:contentDescription for my ImageView android:contentDescription="@string/desc" Android Lint support in ADT 16 throws this warning to ensure that image widgets provide a contentDescription This defines text that briefly describes the 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.

这个链接的解释是:易用性,它的影响和开发资源

Many Android users have disabilities that require them to interact with their Android devices in different ways. These include users who have visual, physical or age-related disabilities that prevent them from fully seeing or using a touchscreen. Android provides accessibility features and services for helping these users navigate their devices more easily, including text-to-speech, haptic feedback, trackball and D-pad navigation that augments their experience. Android application developers can take advantage of these services to make their applications more accessible and also build their own accessibility services.

这个指南是为了让你的应用更容易访问:让应用更容易访问

Making sure your application is accessible to all users is relatively easy, particularly when you use framework-provided user interface components. If you only use these standard components for your application, there are just a few steps required to ensure your application is accessible: Label your ImageButton, ImageView, EditText, CheckBox and other user interface controls using the android:contentDescription attribute. Make all of your user interface elements accessible with a directional controller, such as a trackball or D-pad. Test your application by turning on accessibility services like TalkBack and Explore by Touch, and try using your application using only directional controls.

其他回答

按照这个链接的解决方案:Android Lint内容描述警告

Resolved this warning by setting attribute android:contentDescription for my ImageView android:contentDescription="@string/desc" Android Lint support in ADT 16 throws this warning to ensure that image widgets provide a contentDescription This defines text that briefly describes the 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.

这个链接的解释是:易用性,它的影响和开发资源

Many Android users have disabilities that require them to interact with their Android devices in different ways. These include users who have visual, physical or age-related disabilities that prevent them from fully seeing or using a touchscreen. Android provides accessibility features and services for helping these users navigate their devices more easily, including text-to-speech, haptic feedback, trackball and D-pad navigation that augments their experience. Android application developers can take advantage of these services to make their applications more accessible and also build their own accessibility services.

这个指南是为了让你的应用更容易访问:让应用更容易访问

Making sure your application is accessible to all users is relatively easy, particularly when you use framework-provided user interface components. If you only use these standard components for your application, there are just a few steps required to ensure your application is accessible: Label your ImageButton, ImageView, EditText, CheckBox and other user interface controls using the android:contentDescription attribute. Make all of your user interface elements accessible with a directional controller, such as a trackball or D-pad. Test your application by turning on accessibility services like TalkBack and Explore by Touch, and try using your application using only directional controls.

警告确实很烦人,在许多(大多数!)情况下,对于各种装饰性的ImageViews,没有必要使用contentDescription。解决这个问题最根本的方法就是告诉Lint忽略这个检查。在Eclipse中,转到Preferences中的“Android/Lint Error Checking”,找到“contentDescription”(它在“Accessibility”组中),并将“Severity:”更改为“Ignore”。

Add

tools:ignore="ContentDescription"

为了你的形象。确保您有xmlns:tools="http://schemas.android.com/tools" . 在根布局中。

接下来,对于纯装饰性的图形元素,最好的解决方案是使用:

android:importantForAccessibility="no"

如果您的最小SDK版本至少是16,这是有意义的,因为运行较低版本的设备将忽略此属性。

如果你坚持支持旧版本,你应该使用(就像其他人已经指出的那样):

android:contentDescription="@null"

来源:https://developer.android.com/guide/topics/ui/accessibility/apps #标签元素

添加android:contentDescription="@string/description"(静态或动态)到你的ImageView。 请不要忽略或过滤消息,因为它是有帮助的人使用替代输入法,因为他们的残疾(如TalkBack, Tecla Access Shield等)。