我在 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:
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 - XML 中的“图像上缺少 contentDescription 属性”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9730673/