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

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

问题描述

我在eclipse中发现关于 [Accessibility] Missing imageDescription属性在图像上的警告。这个警告显示在下面的XML代码中的第5行(声明 ImageView )。



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



这是我的XML文件:

 <?xml version =1.0encoding =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内容描述警告


通过为我的ImageView设置属性android:contentDescription
解决了此警告



android:contentDescription =@ string / desc



ADT 16中的Android Lint支持会将此警告提示给确保
图像小部件提供contentDescription



这定义了简要描述视图内容的文本。这个
属性主要用于辅助功能。由于某些视图不是
具有文本表示,此属性可用于提供
这样的。



非文字小部件(如ImageViews和ImageButtons)应使用
contentDescription属性指定
小部件的文本描述,以便屏幕阅读器和其他辅助工具可以
充分描述用户界面。


此链接说明: 可访问性,它的影响和开发资源


许多Android用户有残疾,要求他们互动
与他们的Android设备以不同的方式。这些包括
具有视觉,身体或年龄相关残疾的用户,以防止他们完全看到或使用触摸屏



Android提供可访问性功能和服务帮助这些
用户更轻松地导航他们的设备,包括文字转语音,
触觉反馈,轨迹球和D-pad导航,增加他们的
体验。 Android应用程序开发人员可以利用这些
服务来使他们的应用程序更易于访问,还可以构建
自己的辅助服务。


本指南旨在使您的应用可访问: 使应用程序更易于访问


确保您的应用程序是可访问的所有用户相对
容易特别是当您使用框架提供的用户界面
组件时。如果您只为
应用程序使用这些标准组件,则只需执行几个步骤即可确保您的
应用程序可访问:


  1. 标记您的 ImageButton ImageView / em> 复选框 和其他用户
    界面控件使用 android:contentDescription 属性


  2. 使用方向性
    控制器(如轨迹球或D-pad)可以访问所有用户界面元素。 >


  3. 通过开启辅助功能(如TalkBack
    )和触摸浏览
    来测试您的应用,并尝试仅使用方向控件使用您的应用程序。 p>




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.

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.

解决方案

Follow this link for solution: 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.

This link for explanation: 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.

This guide is for making your app accessible: 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.

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

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