XML 中的“图像上缺少 contentDescription 属性" [英] 'Missing contentDescription attribute on image' in XML

查看:21
本文介绍了XML 中的“图像上缺少 contentDescription 属性"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Eclipse 中收到关于 [Accessibility] 图像上缺少 contentDescription 属性 的警告.此警告显示在下面 XML 代码的第 5 行(声明 ImageView).

I get an warning about [Accessibility]Missing contentDescription attribute on image in eclipse. This warning show at line 5 (declare ImageView) in XML code below.

这在构建和运行我的应用程序时不会出错.但我真的很想知道为什么我会收到这个警告.

This not make any error when build and run my application. But I really want to know why i get this warning.

这是我的 XML 文件:

This is my XML file:

<?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>

请帮助我解决这个问题,感谢您的阅读.

Please help me regarding this and thanks for your reading.

推荐答案

点击此链接获取解决方案: Android Lint contentDescription 警告

通过设置属性 android:contentDescription 解决了这个警告对于我的 ImageView

Resolved this warning by setting attribute android:contentDescription for my ImageView

android:contentDescription=@string/desc"

android:contentDescription="@string/desc"

ADT 16 中的 Android Lint 支持抛出此警告以确保图像小部件提供内容描述

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.

像 ImageViews 和 ImageButtons 这样的非文本小部件应该使用contentDescription 属性来指定文本的描述小部件,以便屏幕阅读器和其他辅助工具可以充分描述用户界面.

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.

这个解释链接: 可访问性,就是影响和开发资源

许多 Android 用户都有残疾,需要他们进行互动以不同的方式使用他们的 Android 设备.其中包括以下用户有视力、身体或年龄相关的残疾,以防止他们从完全看到或使用触摸屏.

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 提供辅助功能和服务来帮助这些用户更轻松地导航他们的设备,包括文本到语音,触觉反馈、轨迹球和方向键导航,增强了他们的经验.Android 应用程序开发人员可以利用这些服务,使他们的应用程序更易于访问并构建他们自己的无障碍服务.

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:

  1. 标记您的ImageButtonImageViewEditTextCheckBox 和其他用户使用 android:contentDescription 属性的界面控件.

  1. 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.

通过打开 TalkBack 等无障碍服务来测试您的应用程序和触摸探索,并尝试仅使用方向控件来使用您的应用程序.

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

这篇关于XML 中的“图像上缺少 contentDescription 属性"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆