
昨天在YouTube Android Developer频道看了一个关于Android Studio使用技巧的视频-Android Studio: (About) 10 Things You (Probably) Didn’t Know You Could Do,今天试了下感觉不错,可以提高开发效率,在这里整理了一下,希望可以给大家带来帮助。
1.自动处理Import
在开发过程当中,经常碰到无用的Import需要清理或者新增类需要添加Import,这时候要么遗忘删除,导致产生无用的代码行,或者需要使用快捷键新增,非常不方便,Android Studio自身就提供自动处理功能。
使用方式
Preference->Editor->General->Auto Import

2.拓展选中的内容至下一个内容
在开发过程中遇到需要选中整行,一般都需要鼠标的帮助,或者按住Shift+<-,这时候可以利用Option+↑,如果按多次,会选中整块内容。
使用方式
Option+↑


3.移动代码行
使用方式
Shift+Option+↑/↓
4.用Live Templates来完成输入的转换
有些代码可以通过模板代码生成,加快开发效率。
使用方式
通过输入“fori”来输出关于for循环的模板代码。


关于Live Templates的具体介绍,可以查看Android Studio Live Templates,或者idea-live-templates来了解Android Studio默认的Live Templates。
5.断点日志输出
有时候我们只是希望查看断点的输出,而又不希望Debug,阻塞运行,这时候就可以利用断点进行日志输出。
使用方式
对需要输出的地方打断点->Shift+Command+F8->在Log evaluated expression里输入需要输出的日志

然后就可以在Debug模式下运行,无阻塞的在Console里查看输出日志。

6.断点输出格式自定义
有时候我们打断点看数据对象输出的时候会被很多数据干扰,甚至有时候需要点击进入查看,非常不方便,如下图。

这时候我们就可以对断点数据输出格式进行自定义

这时候我们可以定义输出内容,方便查看。
使用方式
在断点输出处右键->View as->Create->在Use following expression里面输入需要输出的内容


这样我们就能在断点处很清晰看到输出的内容

7.搜索Action或者Option
使用方式
Shift+Command+A
8.自定义搜索结构
使用方式
Shift+Command+A->Search Structurally->自定义搜索结构->Find




9.自定义结构搜索检查模板
我们在使用Android Studio的时候,有时候会遇到一些代码警告,例如:

引导开发人员写出符合规范的代码,我们还可以自定义代码检测警告。
使用方式
Preference->Editor->Inspections->General->Structural Search Inspection->Add Search Template





10.自定义结构替换检查模板
除了上面第9提到的代码检测,我们还能直接建议开发者修改方式。如图


使用方式
Preference->Editor->Inspections->General->Structural Search Inspection->Add Replace Template




总结
好的工具和方法可以提高我们的工作效率,让我们有更多的时间花在更有意义的事情上面,比如约会,哦,不对,是写出更高效和简洁的代码。有好的工具也欢迎大家留言分享,谢谢。
参考资料
官方视频
Android Studio Live Templates
idea-live-templates
Android Studio Tips and Tricks
可以随意转发,也欢迎关注我的简书,我会坚持给大家带来分享。
网友评论