Android Lint contentDescription warning

后端 未结 11 1710
情书的邮戳
情书的邮戳 2020-12-07 17:03

I am getting warning as \"[Accessibility] Missing contentDescription attribute on image\" for imageview. while using android lint

What does that mean?

相关标签:
11条回答
  • 2020-12-07 17:35

    Another option is to suppress the warning individually:

    xmlns:tools="http://schemas.android.com/tools"  (usually inserted automatically)
    tools:ignore="contentDescription"
    

    Example:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        tools:ignore="contentDescription" >
    
           <ImageView
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:padding="5dp"
                android:src="@drawable/icon" />
    
    0 讨论(0)
  • 2020-12-07 17:40

    Since I need the ImageView to add an icon just for aesthetics I've added tools:ignore="ContentDescription" within each ImageView I had in my xml file.

    I'm no longer getting any error messages

    0 讨论(0)
  • 2020-12-07 17:43

    I recommend you to add the contentDescription.

    android:contentDescription="@string/contentDescriptionXxxx"
    

    but, let's be realistic. Most people don't maintain literal for accessibility. Still, with little effort, you can implement something to help people with disability.

    <string name="contentDescriptionUseless">deco</string>
    <string name="contentDescriptionAction">button de action</string>
    <string name="contentDescriptionContent">image with data</string>
    <string name="contentDescriptionUserContent">image from an other user</string>
    

    .

    The most important thing the blind user will need to know is "Where is the button that I need to click to continue"

    Use contentDescriptionAction for anything clickable.

    use contentDescriptionContent for image with information (graph, textAsImage, ...)

    use contentDescriptionUserContent for all user provided content.

    use contentDescriptionUseless for all the rest.

    0 讨论(0)
  • 2020-12-07 17:44

    Disabling Lint warnings will easily get you into trouble later on. You're better off just specifying contentDescription for all of your ImageViews. If you don't need a description, then just use:

    android:contentDescription="@null"
    
    0 讨论(0)
  • 2020-12-07 17:44

    Go to Gradle file (module app), add below code block

    android {
        ... 
        lintOptions {
            disable 'ContentDescription'
        }
        ...
    }
    

    No more warning! happy coding

    0 讨论(0)
  • 2020-12-07 17:46

    Since it is only a warning you can suppress it. Go to your XML's Graphical Layout and do this:

    1. Click on the right top corner red button

      enter image description here

    2. Select "Disable Issue Type" (for example)

      enter image description here

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题