如何在Android Kotlin中禁止对字符串常量进行拼写检查?

Oll*_*e C 6 android kotlin android-lint android-studio

Android Lint将此代码示例中的字符串常量用作“ dWQGSCDx”上的拼写错误。根据文档,我应该使用@SupressLint(“ Typos”)来抑制它,但那没有实现。我看到其他人建议使用@SuppressWarnings,但这也不起作用。

/**
 * Constants.kt
 */

import android.annotation.SuppressLint

@SuppressLint("Typos")
@SuppressWarnings("SpellCheckingInspection")    
const val SOME_STRING_VALUE = "...dWQGSCDx..."
Run Code Online (Sandbox Code Playgroud)

请注意,这是一个文件作用域的全局常量,它不在类内部,因此不能在包含的类上放置注释。

如何在不完全禁用拼写检查且没有在字典中添加“拼写错误”文本的情况下抑制此常量定义的拼写检查?

Bor*_*edo 8

在 Kotlin 中,您可以使用下面的注解@Suppress代替这个警告@SuppressWarnings

@Suppress("SpellCheckingInspection")
Run Code Online (Sandbox Code Playgroud)

  • 您可以在 Android Studio 或 IntelliJ 中的“首选项”-“编辑器”-“检查”中禁用拼写检查 (2认同)