首页 > 解决方案 > 为什么我在 android studio 中没有看到硬编码文本的任何 lint 错误

问题描述

在阅读 Lint 工具时,我尝试在 android studio 中的一个简单项目上对其进行测试。刚刚创建了一个带有空活动的新项目。mainActivity 的 xml 如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

和 Mainactivity.java :

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

当我尝试运行分析>>检查代码>>整个项目时,从android studio;它在检查结果中显示以下内容:检查结果图像

它不应该还显示用于 TextViews 文本的硬编码文本(“Hello World!”)的警告吗?

由于我没有收到警告,因此我尝试在设置>>编辑器>>检查中更改严重级别,如图所示。但是,检查结果还是一样的。没有警告或错误。

我哪里错了?

标签: androidlint

解决方案


发生这种情况是因为字符串Hello World!一种特殊情况

if (value == "Hello World!") {
    // This is the default text in new templates. Users are unlikely to
    // leave this in, so let's not add warnings in the editor as their
    // welcome to Android development greeting.
    return
}

推荐阅读