android - 如何使用 lintOptions 在 gradle 上禁用 'contentDescription' 警告?

标签 android lint android-lint

我想禁用此警告:

[Accessibility] Missing 'contentDescription' attribute on image

我知道解决方案 android:contentDescription:"@null" .但我希望能够完成整个项目,而不是在我的每个 ImageView 上。

关于 documentation of tools android ,他们提倡这样做:

android {
    lintOptions {
        disable 'TypographyFractions','TypographyQuotes'
        ...
    }
}

我的问题是这个警告“contentDescription attribute on image”的 lint 选项的名称是什么?


编辑,我的解决方案:

点击Suppress with @SuppressLint (Java) or tools:ignore (XML)

此按钮将此添加到您的 <ImageView .. /> :

tools:ignore="ContentDescription"

所以你只需要在你的 build.gradle 上添加这个 lintOptions :

android {
    lintOptions {
        disable 'ContentDescription'
    }
}

最佳答案

我认为您也可以在您的 gradle 配置中禁用它。 您可以找到 Lint 问题列表 here .如果您检查它,您可以看到它包含 TypographyFractions 并且还包含 ContentDescription。请注意,我没有尝试过它们,但我认为它应该有效。

所以在我看来你应该按照以下方式来做:

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

关于android - 如何使用 lintOptions 在 gradle 上禁用 'contentDescription' 警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39169243/

相关文章:

java - 该 Realm 的架构中缺少该类

android - 在哪里可以找到 Android : constant value in source code?

java - 如何在网络请求中将日期格式化为字符串

android - 升级到 Android Studio 3.0.1 后,XML 属性中的值不再被视为有效

Android Lint - 如何隐藏警告 'The resource Xxx appears to be unused'

android - isSpeakerphoneOn 停止在 Android 11 设备上运行

css - 我缺少什么渐变?

batch-file - MSDOS .bat 文件的静态分析器,与 NT 派生版本的 Windows 兼容?

android - 使用自适应图标时 Lint 中止

带有基线文件的 android lintoptions 不工作