'Missing contentDescription attribute on image' in XML

后端 未结 9 1967
挽巷
挽巷 2020-11-28 17:49

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

相关标签:
9条回答
  • 2020-11-28 18:29

    If you don't care at all do this:

        android:contentDescription="@null"
    

    Although I would advise the accepted solutions, this is a hack :D

    0 讨论(0)
  • 2020-11-28 18:34

    Updated:

    As pointed out in the comments, setting the description to null indicates that the image is purely decorative and is understood as that by screen readers like TalkBack.

    Old answer, I no longer support this answer:

    For all the people looking how to avoid the warning:

    I don't think android:contentDescription="@null" is the best solution.

    I'm using tools:ignore="ContentDescription" that is what is meant to be.

    Make sure you include xmlns:tools="http://schemas.android.com/tools" in your root layout.

    0 讨论(0)
  • 2020-11-28 18:38

    This warning tries to improve accessibility of your application.

    To disable missing content description warning in the whole project, you can add this to your application module build.gradle

    android {
    
        ...
    
        lintOptions {
            disable 'ContentDescription'
        }
    }
    
    0 讨论(0)
  • 2020-11-28 18:42

    Add android:contentDescription="@string/description" (static or dynamic) to your ImageView. Please do not ignore nor filter the message, because it is helpfull for people using alternative input methods because of their disability (Like TalkBack, Tecla Access Shield etc etc).

    0 讨论(0)
  • 2020-11-28 18:42

    Add

    tools:ignore="ContentDescription"
    

    to your image. Make sure you have xmlns:tools="http://schemas.android.com/tools" . in your root layout.

    0 讨论(0)
  • 2020-11-28 18:46

    It is giving you the warning because the image description is not defined.

    We can resolve this warning by adding this code below in Strings.xml and activity_main.xml

    Add this line below in 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" />
    

    Also add this line in 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>
    
    0 讨论(0)
提交回复
热议问题