本文从 CSDN 搬迁过来
原地址
概述:
现如今开发越来越追求效率和节奏,节省出时间做更多的事情,除了开发技术上的封装等,开发工具的使用技巧也是很重要的。今天主要介绍Android Studio的快速开发。
Postfix completion
1. 介绍:后缀实现
2. 常用后缀介绍
-
.cast强制转换 .if-
.else对if语句的取反 -
.field生成成员变量--------(与ctrl + alt + F类似) -
.fori简单for循环 -
.for使用增强for循环 -
.forr反向for循环 -
.null快速判空 -
.nn/.notnull快速判断非空 .switch-
.inst/.instanceof -
.var生成一个局部变量-------(不多说,直接alt + enter) -
.par为表达式添加括号
注 :下面两个需要添加plugin:android Postfix completion
.log快速打印log-
.toast快速弹toast
3. 更多查看
Settings-->Editor-->General-->Postfix Completion
Live Templates
1. 介绍
活动模板。让您插入频繁使用的或自定义的代码结构,快速、高效、准确地构建到您的源代码文件中。
2. 系统模板
Settings-->Editor-->Live Templates
3. 自定义模板
使用较少
4. 使用技巧
- 快速添加代码到live templates中,选中代码-->Tools-->Save as Live Templates
- 当不记得模板的缩写时,Windows:
ctrl + j-------Mac:cmd + j。有惊喜!!
快捷键
1. 常用快捷键介绍
- Windows / Mac
-
ctrl + shift + A/cmd + shift + A查找AS所有动作功能 (超级强大) -
双击shift/双击shift查找工程中的所有文件 (超级强大) -
F3/cmd + G查找下一个,配合ctrl + F使用------ps:按回车键也行 -
shift + F3/cmd + shift + G查找上一个,配合ctrl + F使用 -
ctrl + alt + B/cmd + alt + B找到接口/类的实现类 或实现方法 ,在mvp模式常用 -
F2/F2快速定位错误 -
ctrl + shift + backspace/cmd + shift + backspace回到上次编辑的位置 -
ctrl + shift + V/cmd + shift + v从粘贴簿选择粘贴 -
ctrl + H/cmd + H查看class的继承结构 -
ctrl + alt + H/cmd + alt + H查看方法的层次调用关系 -
ctrl + P/cmd + P查看方法的参数类型 -
ctrl + Q/cmd + Q快速查看简要文档
-
2. 系统默认快捷键
1) 普通类型
| description | 解释 | Windows/Linux | Mac |
|---|---|---|---|
| Open settings dialogue | 快速打开设置 | Ctrl + Alt + S | Cmd + , (comma) |
| Open project structure dialog | 打开项目结构 | Ctrl + Alt + Shift + S | Cmd + ; (semicolon) |
2) 追踪和搜索
| description | 解释 | Windows/Linux | Mac |
|---|---|---|---|
| Find | 查找 | Ctrl + Alt + S | Cmd + , (comma) |
| Search everything (including code and menus) | 查找所有 | 点击shift两次即可搜索 | 点击shift两次即可搜索 |
| Find next | 顺序向下查找 | F3 | Cmd + G |
| Find action | 查找功能,超级强大,as的所有功能可以通过该功能来查找 | Ctrl + Shift + A | Cmd + Shift + A |
| Find class | 快速找到类并打开文件 | Ctrl + N | Cmd + O |
| Find file (instead of class) | 快速查找文件 | Ctrl + Shift + N | Cmd + Shift + O |
| Find in path | 在项目下的所有路径查找 | Ctrl + Shift + F | Cmd + Shift + F |
| Recently opened files pop-up | 列出最近打开的文件 | Ctrl + E | Cmd + E |
| Recently edited files pop-up | 列出最近编辑过的文件 | Ctrl + Shift + E | Cmd + Shift + E |
| Go to last edit location | 回到最近一次编辑的位置 | Ctrl + Shift + Backspace | Cmd + Shift + Backspace |
| Close active editor tab | 关闭当前编辑的文件 | Ctrl + F4 | Cmd + W |
| Open type hierarchy | 打开类型层次关系 | Ctrl + H | Cmd + H |
| Open method hierarchy | 打开方法层次关系 | Ctrl + Shift + H | Cmd + Shift + H |
| Open call hierarchy | 打开调用层次关系 | Ctrl + Alt + H | Cmd + Option + H |
3) 写代码常用快捷键
| description | 解释 | Windows/Linux | Mac |
|---|---|---|---|
| Generate code (getters, setters, constructors, hashCode/equals, toString, new file, new class) | 快速生成各种方法 | Alt + Insert | Cmd + N |
| Override methods | 显示所有可以重写的方法 | Ctrl + O | Cmd + O |
| Implement methods | 显示所有可以实现的方法 | Ctrl + I | Cmd + I |
| Surround with (if…else / try…catch / etc.) | 快速为语句生成if else,try catch for循环等 | Ctrl + Alt + T | Cmd + Option + T |
| Delete line at caret | 删除光标所在行 | Ctrl + Y | Cmd + Backspace |
| Duplicate current line or selection | 快速产生新的当前行,或者新的多行代码 | Ctrl + D | Cmd + D |
| Quick documentation lookup | 快速查看简要文档 | Ctrl + P | Cmd + P |
| Go to declaration (directly) | 找到变量或方法声明处 | Ctrl + B or Ctrl + Click | Cmd + B or Cmd + Click |
| Go to implementations | 找到一个接口的实现类,接口方法的是实现处 | Ctrl + Alt + B | Cmd + Alt + B |
| Go to super-method/super-class | 找到父类或父类方法 | Ctrl + U | Cmd + U |
| Toggle project tool window visibility | 显示或隐藏as左边的项目窗口 | Alt + 1 | Cmd + 1 |
| Comment/uncomment with line comment | 快速单行注释或去除注释 | Ctrl + / | Cmd + / |
| Comment/uncomment with block comment | 多行注视或除去多行注释 | Cmd + Shift + / | Cmd + Shift + / |
| Project quick fix (show intention actions and quick fixes) | 给出当前问题的多种解决方法(该方法非常常用) | Alt + Enter | Option + Enter |
| Reformat code | 格式化代码 | Ctrl + Alt + L | Cmd + Option + L |
| Next/previous highlighted error | 找到下一个/上一个错误 | F2 / Shift + F2 | F2 / Shift + F2 |
4) 编译运行
| description | 解释 | Windows/Linux | Mac |
|---|---|---|---|
| Build | 编译 | Ctrl + F9 | Cmd + F9 |
| Build and run | 编译并运行 | Shift + F10 | Cmd + R |
5) 调试
| description | 解释 | Windows/Linux | Mac |
|---|---|---|---|
| Debug | debug模式运行 | Shift + F9 | Shift + F9 |
| Step over | 下一步 | F8 | F8 |
| Step into | F7 | F7 | |
| Smart step into | Shift + F7 | Shift + F7 | |
| Resume program | 恢复程序 | F9 | Cmd + Option + R |
6) 修改
| description | 解释 | Windows/Linux | Mac |
|---|---|---|---|
| Safe delete | 安全删除 | Alt + Delete | Cmd + Delete |
| Extract method | 提取方法 | Ctrl + Alt + M | Cmd + Option + M |
| Extract variable | 提取变量 | Ctrl + Alt + V | Cmd + Option + V |
| Extract field | 提取全局变量 | Ctrl + Alt + F | Cmd + Option + F |
| Extract constant | 提取常量 | Ctrl + Alt + C | Cmd + Option + C |
| Extract parameter | 提取参数 | Ctrl + Alt + P | Cmd + Option + P |
7) 版本控制/本地历史
| description | 解释 | Windows/Linux | Mac |
|---|---|---|---|
| Commit project to VCS | 提交 | Ctrl + K | Cmd + K |
| Update project from VCS | 从VCS中更新项目 | Ctrl + T | Cmd + T |
| View recent changes | 查看最近修改 | Alt + Shift + C | Option + Shift + C |
| Open VCS popup | 打开版本控制设置窗口 | Alt + ` (backquote) | Cmd + V |
扩展
自定义快捷键
主要在用系统默认的。。。
插件
这里就不介绍了。常用的就butterknife、gsonformat等。可以看看我参考的这篇博客。
就说这么多了,欢迎小伙伴指出不足之处。