android - XML 中的“图像上缺少 contentDescription 属性”

标签 android eclipse warnings accessibility android-imageview

我在 Eclipse 中收到关于 [Accessibility]Missing contentDescription 属性 on image 的警告。此警告显示在下面 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 contentDescription warning

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.

这个解释链接: Accessibility, It's Impact and Development Resources

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 Apps More Accessible

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:

  1. Label your ImageButton, ImageView, EditText, CheckBox and other user interface controls using the android:contentDescription attribute.

  2. Make all of your user interface elements accessible with a directional controller, such as a trackball or D-pad.

  3. Test your application by turning on accessibility services like TalkBack and Explore by Touch, and try using your application using only directional controls.

关于android - XML 中的“图像上缺少 contentDescription 属性”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9730673/

相关文章:

android - 根 Activity 是堆栈中的当前第一个 Activity 还是 list 中指定为启动 Activity 的 Activity ?

android - 我将如何在 XML 中重新创建此标准均衡器布局?

objective-c - Xcode/iOS——摆脱特定常量的弃用警告?

php - 引用 - 这个错误在 PHP 中意味着什么?

android - WorkManager 中如何减少 PeriodicWorkManager 的时间

java - 避免在 Eclipse 中发布资源后重新启动服务器?

Eclipse 显示注释错误但构建成功

regex - eclipse search - 正则表达式查找带回车的文件开头/结尾

ms-access - 如何摆脱VBA安全警告

java - 如何识别 Android App 是否正在进行自动化 ui 测试?