本文列舉出一些可以提高整體效率的Android Studio技巧和資源。
顯然有太多太多這方面的東西,但是為了文章的簡潔性,我把它限制在50個以內(nèi),希望你能喜歡!
視覺效果
1. Android Logcat的Material顏色主題。

要改變Android Studio的Logcat你需要這樣做:進入Preferences (Windows上是Settings / Linux machines) → Editor → Colors & Fonts → Android Logcat,然后為每種類型的log設(shè)置前景顏色(foreground)。
我使用的material顏色:
- Assert #BA68C8
- Debug #2196F3
- Error #F44336
- Info #4CAF50
- Verbose #BBBBBB
- Warning #FF9800
注意里面有幾個現(xiàn)有的主題,可以直接修改現(xiàn)有主題(不建議),或者點擊save as按鈕拷貝一個主題并改名為Material theme Color然后再改變每種類型log的顏色。
2. 防止當(dāng)前應(yīng)用崩潰時Logcat清除log。
在Android Monitor面板的右上方點擊下拉菜單中的Edit filter configuration:
注意是在工程界面的底部Android Monitor面板,而不是單獨的Android Monitor工具中。
3. 使用一個適合自己的代碼主題 (IntelliJ / Android Studio).
找到Preferences → Code Style → Java,在Scheme下拉菜單中你可以選擇一個代碼風(fēng)格(或者設(shè)置一個新的)。
有兩個風(fēng)格值得專門提一下:
- Square Java Code Styles with Android
-
Google Java Code Style.
你可以按照下面gif圖中的做法導(dǎo)入主題:
[站外圖片上傳中...(image-49207a-1547091394703)]
4. 使用分屏提高效率

要打開這個功能,右鍵主屏幕的選項卡(tab)選擇 Split Vertically / Horizontally。

但是為了盡量提高效率我們需要設(shè)置一個自定義的快捷方式。為此找到到Preferences → Keymap,搜索Split Vertically。然后打開一個上下文菜單,點擊Add Keyboard Shortcut。
我的分屏(vertical)快捷鍵設(shè)置的是control + alt + v。做法如下面的gif圖所示。同樣的你還可以為 horizontal split設(shè)置快捷鍵。
[站外圖片上傳中...(image-d5cd38-1547091394703)]
5. 無干擾模式
你可以到View → Enter Distraction Free Mode里啟用它

在無干擾模式下,編輯器占據(jù)了整個IntelliJ IDEA窗口,沒有任何tab或者工具按鈕。代碼居中顯示。[IntelliJ Idea Viewing Modes]

6. 使用Live Templates
-
你可以使用快捷鍵:cmd + j (Windows / Linux: ctrl + j)。
-
可以使用已經(jīng)定義好了的Live Templates,比如Toasts 或者if語句。
[站外圖片上傳中...(image-66260a-1547091567087)]
可以使用自定義的templates。這里是Reto Meier的一篇不錯的參考文章。你也可以參考IntelliJ IDEA的文檔。
快捷鍵以及有用的命令
1. 最有用的命令是搜索命令的命令:cmd + shift + a (Windows / Linux: ctrl + shift + a)。
假設(shè)你想關(guān)閉當(dāng)前tab卻不知道怎么做,你只需輸入close你就可以得到一個正確的快捷鍵/命令。
2. 選擇最近的復(fù)制粘貼(管理剪切版):cmd + shift + v (Windows / Linux: ctrl + shift + v)。
默認有5個最近的復(fù)制/粘貼元素。

The depth of the Clipboard stack is configured in the Limits section on the Editor page of the Settings dialog box. When the specified number is exceeded, the oldest entry is removed from the list. [Cutting, Copying and Pasting in IntelliJ IDEA]
3. 啟用多光標(biāo)功能:control + g (alt + j for Windows / Linux)。
Bartek Lipinski在Medium上提供了一篇關(guān)于這個功能的詳細文章。強烈推薦!
4. 打開一個類: cmd + o (Windows / Linux: ctrl + n)。
5. 打開任意文件: cmd + shift + o (Windows / Linux: ctrl + shift + n)。
6.打開symbol:cmd + option + o (Windows / Linux: alt + shift + n)。
7. 跳到實現(xiàn):cmd + option + b (Windows / Linux: ctrl + alt + b)。
假如你有一個interface。通過點擊接口的名字,然后按下快捷鍵就可以跳轉(zhuǎn)到這個接口的實現(xiàn)。如果有多個實現(xiàn)會出現(xiàn)下拉選擇。
8. 跳轉(zhuǎn)到定義:cmd + b (Windows / Linux: ctrl + b)。
可以讓你快速跳轉(zhuǎn)到一個類,方法或者變量被定義的地方。
9. 跳轉(zhuǎn)到類型定義處:control + shift + b (Windows / Linux:
ctrl + shift + b)。
假設(shè)你定義了:
Employee employee = new Employee(“Michal”);
當(dāng)你的插入符號在employee上,這時你按下快捷鍵,你將跳轉(zhuǎn)到Employee類中。
10. 跳轉(zhuǎn)到super: cmd + u (Windows / Linux: ctrl + u)。
比如,你重寫了一些方法,當(dāng)你的插入符號在方法名上,按下這個快捷鍵你將跳轉(zhuǎn)到parent的這個方法。
11. Move between tabs: cmd + shift + [ (move left) or cmd + shift + ](move right) (Windows / Linux: alt + ← / →).
12. Move between Design / Text tabs in layout’s view: control + shift + ← / → (Windows / Linux: alt + shift + ← / →).
13. 關(guān)閉當(dāng)前的tab:cmd + w (Windows / Linux: ctrl + shift + a)。
14. 隱藏所有窗口:cmd + shift + F12 (Windows / Linux:
ctrl + shift + F12)。
15. 最小化 Android Studio instance: cmd + m (Windows / Linux: ctrl + m)。
16. 格式化代碼: cmd + option + l (Windows / Linux: ctrl + alt + l)。
17. Auto-indent lines: control + option + i (Windows / Linux: ctrl + alt + i).
18. 實現(xiàn)接口的方法: control + i (Windows / Linux: ctrl + i)。
假設(shè)你要實現(xiàn)一個接口。這個快捷鍵可以讓你快速導(dǎo)入這個接口的所有方法。
19. Smart code completion (filters the list of methods and variables by expected type): control + shift + space (Windows / Linux: ctrl + shift + space).
20. 查找: cmd + f (Windows / Linux: ctrl + f)。
21. 查找并替換: cmd + r (Windows / Linux: ctrl + r)。
22. 把一個硬編碼的字符串放到資源文件中:option + return (Windows / Linux: alt + enter)。光標(biāo)必須在這個文字之上時才能使用這個快捷鍵??聪旅娴膅if圖:
[站外圖片上傳中...(image-4d2fb5-1547091394704)]
插件
- Key promoter - 快捷鍵提示插件 當(dāng)你點擊鼠標(biāo)一個功能的時候,可以提示 你這個功能快捷鍵是什么 ,和這個按鈕你的使用頻率.
- String Manipulation - a plugin which provides actions for text manipulation (e.g. toggling styles like camelCase, hyphen-lowercase etc., capitalize text and many more).
- Android Material Design Icon Generator -這個插件幫助你為工程添加Material Design圖標(biāo)。安裝之后使用快捷鍵cmd + shift + m生成一個圖標(biāo)。
-
ButterKnifeZelezny - 一鍵從 布局文件中 生成對于的 View 聲明和 ButterKnife 注解:
[站外圖片上傳中...(image-f3da83-1547091394704)] - IntelliJ/Android Studio Plugin for Android Parcelable boilerplate code generation - 一個根據(jù)類的成員生成Parcelable的插件。
- ADB Idea - 一個幫助你使用adb命令的插件:卸載,殺死,啟動,重啟,清除數(shù)據(jù)等命令。
- Genymotion plugin - 一個讓你可以在Android Studio中創(chuàng)建和開啟Genymotion虛擬設(shè)備的插件。
- Android Methods Count - a plugin that parses your Android library dependencies and shows the methods count as an handy hint.
- Git Flow Integration - a plugin for introducing a Git Flow branching model.
- Builder plugin - a plugin (from Square) that generates a static nested Builder for a class.