Warm tip: This article is reproduced from stackoverflow.com, please click
android android-studio xml lint text-size

Suppressing Lint Warnings in XML

发布于 2020-04-03 23:37:30

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?

Questioner
jerry
Viewed
58
laalto 2016-08-17 22:49

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>