注意:本篇文章是本人阅读相关文章所写下的总结,方便以后查阅,所有内容非原创,侵权删。
Android lint是一个代码扫描工具,能够帮助我们识别代码结构存在的问题。
具体使用参考 Android 性能优化:使用 Lint 优化代码、去除多余资源
目录
- Android Studio 中使用 Lint
- 提升、降低Lint代码检查结果问题的等级
- 自动删除查找出来的无用资源文件
- 忽略Lint警告
1. Android Studio 中使用 Lint
打开Lint
主要看红框里面的内容
比如
2. 提升、降低Lint代码检查结果问题的等级
提示弱,如何增加提示等级?
打开 Preferences/Settings,搜索 Inspections,会出现 Lint 的检测配置页面:
要修改拼写的警告等级,搜索“spelling”:
Unused Entry:没有使用的属性,灰色,很不起眼
Typo:拼写错误,绿色波浪下划线,也不太起眼
Server Problem:服务器错误?好像不是
Info:注释文档,绿色,比较显眼
Weak Warning:比较弱的警告,提示比较弱
Warning:警告,略微显眼一点
Error:错误,最显眼的一个
成功
3. 自动删除查找出来的无用资源文件
点击 Android Studio 工具栏 -> Analyze -> Run Inspection By Name..,输入要检测的内容,这里是无用资源:
然后选择 Unused resources,再选择范围后就开始检测。
检测出无用文件,点击Remove All Unused Resources进行清除。
4. 忽略Lint警告
java代码忽略
利用@SuppressLint("NewApi")或者@SuppressLint("all")
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
xml文件忽略
xml 中声明 tools 命名空间
使用 tools:ignore=”忽略的警告名”
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="all"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white">