如何抑制资源xml文件中特定行/字符串的lint?

Cal*_*ark 3 xml android translation lint suppress

在Android上,我想在string.xml或其他资源文件上抑制特定字符串值或特定行的lint.

<string name="suppress_lint_string">Suppress this String</string>

<string name="dont_suppress_lint_string">Don\'t Suppress this String</string>
Run Code Online (Sandbox Code Playgroud)

我想对特定字符串和布局的特定部分执行特定的lint抑制,例如缺少特定字符串的翻译,这些字符串在语言之间并不重要.

Edu*_*ysh 8

如果要在不抑制整个文件的情况下禁止特定字符串中的特定规则,则可以使用注释.

strings.xml中

<?xml version="1.0" encoding="utf-8"?>
<resources>    

    <!--suppress MissingTranslation -->
    <string name="suppress_lint_string">ignore my translation</string>
    ...

</resources>
Run Code Online (Sandbox Code Playgroud)

您可以使用任何其他lint规则替换MissingTranslation.

http://tools.android.com/tips/lint/suppressing-lint-warnings

  • 请注意,您必须在 lint 规则前添加“AndroidLint”前缀。因此,如果要抑制未使用的字符串资源,请添加:`&lt;!--suppress AndroidLintUnusedResources --&gt;` (5认同)