Search code examples
androidxmlandroid-studiolinttext-size

Suppressing Lint Warnings in XML


My understanding is that suppressing individual warnings can be done in XML by adding an ignore property, e.g.

xmlns:tools="http://schemas.android.com/tools"
tools:ignore="SpUsage"
android:textSize="30dp"

This works fine when the text size is directly specified. But when I use a reference to a dimension, e.g.

android:textSize="@dimen/largeTextSize"

Lint produces a warning in spite of the ignore.

Let's assume that the given case is a justified exception, and that the guidance on generally preferring sp dimensions over dp for text is well understood and followed.

Because this is an exception I do not want to disable the warning globally. How can I do it locally?


Solution

  • You need to add the suppression on the dimen value resource:

    <resources xmlns:tools="http://schemas.android.com/tools">
         <dimen name="largeTextSize" tools:ignore="SpUsage">123dp</dimen>
    </resources>