我得到一个关于[可访问性]在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>

请帮助我,感谢您的阅读。


当前回答

Add

tools:ignore="ContentDescription"

为了你的形象。确保您有xmlns:tools="http://schemas.android.com/tools" . 在根布局中。

其他回答

接下来,对于纯装饰性的图形元素,最好的解决方案是使用:

android:importantForAccessibility="no"

如果您的最小SDK版本至少是16,这是有意义的,因为运行较低版本的设备将忽略此属性。

如果你坚持支持旧版本,你应该使用(就像其他人已经指出的那样):

android:contentDescription="@null"

来源:https://developer.android.com/guide/topics/ui/accessibility/apps #标签元素

如果你一点都不在乎,就这样做:

    android:contentDescription="@null"

虽然我会建议大家接受的解决方案,但这是一个hack:D

此警告试图提高应用程序的可访问性。

要在整个项目中禁用缺失内容描述警告,可以将其添加到应用程序模块build.gradle中

android {

    ...

    lintOptions {
        disable 'ContentDescription'
    }
}

它给你警告,因为图像描述没有定义。

我们可以通过在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.