Android Lint contentDescription warning

后端 未结 11 1771
情书的邮戳
情书的邮戳 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:48

    For graphical elements that are purely decorative, set their respective android:contentDescription XML attributes to "@null".

    If your app only supports devices running Android 4.1 (API level 16) or higher, you can instead set these elements' android:importantForAccessibility XML attributes to "no"

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

    If you want to suppress this warning in elegant way (because you are sure that accessibility is not needed for this particular ImageView), you can use special attribute:

    android:importantForAccessibility="no"
    
    0 讨论(0)
  • 2020-12-07 17:54

    Non textual widgets need a content description in some ways to describe textually the image so that screens readers to be able to describe the user interface. You can ignore the property xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="contentDescription"
    or define the property android:contentDescription="your description"

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

    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 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.

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

    ContentDescription needed for the Android accessibility. Particularly for the screen reader feature. If you don't support Android accessibility you can ignore it with setup Lint.

    So just create lint.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <lint>
    
        <issue id="ContentDescription" severity="ignore" />
    
    </lint>
    

    And put it to the app folder.

    0 讨论(0)
提交回复
热议问题