android - 为什么我在 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!”)的警告吗?
由于我没有收到警告,因此我尝试在设置>>编辑器>>检查中更改严重级别,如图所示。但是,检查结果还是一样的。没有警告或错误。
我哪里错了?
解决方案
发生这种情况是因为字符串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
}
推荐阅读
- python - 我有一些列表,我已经合并了它们,但是我怎样才能按降序排列值并将其作为 STD 呢?
- sql - SQL JOIN COUNT 和 GROUP BY
- python - 如何在 Kafka 中发布字典?
- java - Generate classes from Postgress database with multiple schemas using Cayenne
- cron - crontab 重启作业重启多次而不是一次
- spring-mvc - 通过使用字段名称在 JSP 中获取值
- node.js - Nodejs:在类方法中的异步函数中访问“this”
- android - 折叠工具栏标题在展开时会忽略 textStyle 和 fontStyle
- java - 如何在android中动态设置颜色透明?像 10% 20% 到 100%
- rust - 在 rust 中,如何定义一个全局变量/常量,其值是函数的结果?