北京字典价格联盟

50个Android Studio秘诀、技巧和资源

只看楼主 收藏 回复
  • - -
楼主

版权声明

作者:Michal Bialas

译者:刘志勇

本文由作者授权翻译并发布,未经许可不可转载。

原文地址:https://medium.com/@mmbialas/50-android-studio-tips-tricks-resources-you-should-be-familiar-with-as-an-android-developer-af86e7cf56d2#.badcf6khh

作者撰写本文的初衷,是为了罗列出Android Studio有用的提示、技巧、快捷方式和参考资源,将提高您的整体效率和操作性能。

显然,Android Studio的使用技巧还有很多,还有很多优化、快捷方式等,但作者为了保持这篇文章的简短,限制为50个,希望读者会喜欢这篇文章!

可视化


1. Android Logcat的输出信息颜色主题(Material Colors theme)

要更改Android Studio Logcat,您需要依次点击:Preferences → Editor → Colors & Fonts → Android Logcat,然后更改每种类型日志的前景颜色。(注意,此处Perferences在Windows / Linux 是Settings。)

我的信息颜色如下:

  • Assert #BA68C8

  • Debug #2196F3

  • Error #F44336

  • Info #4CAF50

  • Verbose #BBBBBB

  • Warning #FF9800

2. 防止Android Studio Logcat崩溃,应清除当前应用程序的日志

要做到这一点,您需要到Android Monitor面板在右侧下拉列表中选择Edit filter configuration

3. 将您的IDE(IntelliJ / Android Studio)应用正确的代码样式

依次点击Preferences → Code Style → Java,在Scheme下拉列表中选择您的代码样式(或设置一个新的代码样式)。
有2款风格特别值得一提:

  • Square Java Code Styles with Android

  • Google Java Code Style

您可以导入主题,如下面的gif所示:


4. 使用分屏可提高效率

要打开此功能,您需要在主屏幕的选项卡上单击鼠标右键,然后选择Split Vertically / Horizontally

但为了尽可能高效,我们需要设置一个自定义键盘的快捷方式。要做到这一点,依次点击Preferences → Keymap  并找到Split Vertically。然后打开上下文菜单并单击 Add Keyboard Shortcut

以我为例,对于垂直拆分视图,我增加了control + alt + v。 您也可以为水平分割视图定义快捷方式。

5. 无干扰模式(Distraction Free Mode)

您可以依次点击: View → Enter Distraction Free Mode来开启无干扰模式。

在无干扰模式下,编辑器占用整个IntelliJ IDEA框架,而没有任何编辑器选项卡和工具按钮,代码按中心对齐。 [IntelliJ Idea查看模式] https://www.jetbrains.com/help/idea/2016.2/intellij-idea-viewing-modes.html

6. 使用活动模板

  • 您可以使用快捷方式:cmd + j(Windows / Linux:ctrl + j)。

  • 您可以使用许多已定义的模板,像Toastsif条件。


  • 您可以使用自己的自定义模板。下面是Reto Meier的一篇参考文章。您还可以参考IntelliJ IDEA文档。

    https://medium.com/google-developers/writing-more-code-by-writing-less-code-with-android-studio-live-templates-244f648d17c7#.vifxrypd1


标题快捷方式和命令


1. 最好的、最有用的命令Search for commandcmd + shift + a (Windows / Linux:ctrl + shift + a)。

当你想关闭当前选项卡,不知道该怎么办时,您只需键入:close你会得到一个正确的快捷方式/命令。

2. 从最近的复制/粘贴中选择(管理剪贴簿):
cmd + shift + v(Windows / Linux:ctrl + shift + v)。
默认情况下,最后有5个复制/粘贴项目。

剪贴板堆栈的深度在“设置”对话框的“编辑器”页面的“限制”部分中配置。超过指定的数量时,将从列表中删除最早的条目。 [在IntelliJ IDEA中剪切,复制和粘贴] https://www.jetbrains.com/help/idea/2016.2/cutting-copying-and-pasting.html

3. 启用多光标(multicursor)功能:control + g(Windows / Linux:alt + j)。

有关此功能的详细文章由Bartek Lipinski在Medium网站提供。强烈推荐:

https://android.jlelse.eu/ctrl-g-d94c88cd4475#.ed3x7e91n

4. Open a classcmd + o (Windows / Linux:ctrl + n)。

5. Open any filecmd + shift + o (Windows / Linux:ctrl + shift + n)。

6. Open symbolcmd + option + o (Windows / Linux:alt + shift + n)。

7. Go to implementationcmd + option + b (Windows / Linux:ctrl + alt + b)。  
假设您有一个界面,通过单击接口的名称,然后单击Go to implementation的快捷方式,您将被重定向到实现该接口的类。

8.  Go to declarationcmd + b (Windows / Linux:ctrl + b)。  它允许您快速检查并转到类、方法或变量的声明。

9. Go to type declarationcontrol + shift + b(Windows / Linux:ctrl + shift + b)。
假设您如此定义:
Employee employee = new Employee(“Michal”);
当你的插入符号employee并单击快捷方式时,将会被重定向到Employee类。

10. Go to supercmd + u(Windows / Linux:ctrl + u)。
例如,您重写一些方法。当你在方法名称插入符号,并单击转到Go to super快捷方式,您将被重定向到父方法。

11. Move between tabscmd + shift + [cmd + shift + ] (Windows / Linux:alt + ← / →)。

12. Move between Design / Text tabs in layout’s viewcontrol + shift + ← / →(Windows / Linux:alt + shift + ← / →)。

13. Close a current tab: cmd + w(Windows / Linux:ctrl + shift + a)。

14. Hide all windowscmd + shift + F12 (Windows / Linux:ctrl + shift + F12)。

15. Minimize Android Studio instancecmd + m(Windows / Linux:ctrl + m)。

16. Format your code: cmd + option + l (Windows / Linux:ctrl + alt + l)。

17. Auto-indent linescontrol + option + i (Windows / Linux:ctrl + alt + i)。

18. Implement methodscontrol + i (Windows / Linux:ctrl + i)。
假设您实现了一个接口,然后只需单击此快捷方式,即可快速导入该界面提供的所有方法。

19. Smart code completion(按期望类型过滤方法和变量的列表):control + shift + space (Windows / Linux:ctrl + shift + space)。

20. Findcmd + f(Windows / Linux: ctrl + f)。

21. Find and replacecmd + r(Windows / Linux: ctrl + r)。

22. Move hardcoded strings to resourcesoption + return (Windows / Linux: alt + enter)。
当在文本上使用插入符号时,必须使用快捷方式。检查下面的gif:

如果您在全局使用该快捷方式,IDE将执行Project快速修复(Project quick fix)(显示意图操作和快速修复)。

23. Build and runcontrol + r (Windows / Linux: shift + F10)。


插件


1.Key promoter——帮助您更频繁地使用键盘的插件:https://plugins.jetbrains.com/plugin/4455

2.String Manipulation——一个为文本操作提供操作的插件(例如,切换样式,如camelCase、连字符-小写等、大写文本等还有很多):https://plugins.jetbrains.com/plugin/2162

3.Android Material Design Icon Generator——此插件可帮助您将Material Design图标设置为Android项目。安装后,您可以使用快捷方式:cmd + shift + m以生成图标(默认):https://github.com/konifar/android-material-design-icon-generator-plugin

4.ButterKnifeZelezny——一个简单的插件,允许一键点击创建Butterknife视图注入:https://github.com/avast/android-butterknife-zelezny

5.IntelliJ/Android Studio Plugin for Android Parcelable boilerplate code generation——一个基于类中的字段生成Android Parcelable实现的插件:https://github.com/mcharmas/android-parcelable-intellij-plugin

6.ADB Idea——一个帮助和自动执行adb命令的插件:卸载、杀死、启动、重新启动、清除应用程序和清除应用程序数据并重新启动它:https://github.com/pbreault/adb-idea

7.Genymotion plugin——此插件允许您从Android Studio创建和启动Genymotion虚拟设备:https://www.genymotion.com/plugins/

8.Android Methods Count——一个解析您的Android库所依赖的插件,并显示方法计数作为方便的提示:http://www.methodscount.com/plugins

9.Git Flow Integration——一个用于引入Git Flow分支模型的插件:https://plugins.jetbrains.com/plugin/7315

10.Builder plugin——一个插件(从Square)生成一个类的静态嵌套Builder:https://plugins.jetbrains.com/plugin/7567

资源


1.Philippe Breault:《当代Android Studio秘诀》 https://plus.google.com/collection/wtO0PB

2.《键盘快捷方式参考》https://developer.android.com/studio/intro/keyboard-shortcuts.html

3.Reto Meier:《在Android Studio中你可能不知道能做的十件事》 https://medium.com/google-developers/about-10-things-you-probably-didn-t-know-you-could-do-in-android-studio-de231071b375#.toxstt9em

4.Hadi Hariri:《无鼠标驱策开发》 https://vimeo.com/98922030

5.Philippe Breault:《像老板一样的Android Studio》 https://realm.io/news/360andev-philippe-breault-android-studio-ide-like-boss-structural-search-refactoring-java/

6.《Android Studio 专家 (Android 开发峰会 2015)》 https://www.youtube.com/watch?v=Y2GC6P5hPeA

7. Michael Evans:《Android Studio 秘诀和技巧》 http://michaelevans.org/blog/2016/01/06/android-studio-tips-and-tricks/

8.《遇见Android Studio》 https://developer.android.com/studio/intro/index.html

9. Donn Felker:《Android Studio——秘诀和技巧》 http://www.donnfelker.com/android-studio-tips-and-tricks-part-1/

10.《用Android Studio调试你的App》 https://developer.android.com/studio/debug/index.html

11.《你应该必备的插件——Reddit discussion》 https://www.reddit.com/r/androiddev/comments/3ktqyb/what_are_some_of_your_musthave_plugins_for/

移动平台如何与AR/VR、视频、硬件创新等新技术相结合?Hybrid是否是移动技术的最佳形式?创业公司如何选择适合自己的移动架构?相约ArchSummit北京2016,与来自腾讯、阿里等移动技术专家们一起深入移动架构的选择与思考ArchSummit9折倒计时,点击“阅读原文”了解详情。



举报 | 1楼 回复

友情链接