我得到一个关于[可访问性]在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>
请帮助我,感谢您的阅读。
它给你警告,因为图像描述没有定义。
我们可以通过在Strings.xml和activity_main.xml中添加下面的代码来解决这个警告
在Strings.xml中添加下面这行
<string name="imgDescription">Background Picture</string>
you image will be like that:
<ImageView
android:id="@+id/imageView2"
android:lay`enter code hereout_width="0dp"
android:layout_height="wrap_content"
android:contentDescription="@string/imgDescription"
app:layout_editor_absoluteX="0dp"
app:layout_editor_absoluteY="0dp"
app:srcCompat="@drawable/background1"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp" />
还要在activity_main.xml中添加这一行
android:contentDescription="@string/imgDescription"
Strings.xml
<resources>
<string name="app_name">Saini_Browser</string>
<string name="SainiBrowser">textView2</string>
<string name="imgDescription">BackGround Picture</string>
</resources>
按照这个链接的解决方案: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.