50個安卓開發者應該熟悉的Android Studio技巧和資源

本文列舉出一些可以提高整體效率的Android Studio技巧和資源。

顯然有太多太多這方面的東西,但是爲了文章的簡潔性,我把它限制在50個以內,希望你能喜歡!

視覺效果

1. Android Logcat的Material顏色主題。

1-90Z9yk4rWds8CupDwCo8Rw.png

要改變Android Studio的Logcat你需要這樣做:進入Preferences (Windows上是Settings / Linux machines) → Editor → Colors & Fonts → Android Logcat,然後爲每種類型的log設置前景顏色(foreground)。

我使用的material顏色:

  • Assert #BA68C8

  • Debug #2196F3

  • Error #F44336

  • Info #4CAF50

  • Verbose #BBBBBB

  • Warning #FF9800

注意裏面有幾個現有的主題,可以直接修改現有主題(不建議),或者點擊save  as按鈕拷貝一個主題並改名爲Material theme Color然後再改變每種類型log的顏色。

2. 防止當前應用崩潰時Logcat清除log。

在Android Monitor面板的右上方點擊下拉菜單中的Edit filter configuration:

1-fvHHZ6GNu5nuNQooAi99qQ.gif

注意是在工程界面的底部Android Monitor面板,而不是單獨的Android Monitor工具中。

3. 使用一個適合自己的代碼主題 (IntelliJ / Android Studio).

找到Preferences → Code Style → Java,在Scheme下拉菜單中你可以選擇一個代碼風格(或者設置一個新的)。

有兩個風格值得專門提一下:

你可以按照下面gif圖中的做法導入主題:

1-rDEZ3MCTBMuwFu8ZY6h3Rw.gif

4. 使用分屏提高效率

1-Lxh69qm-4ZZ4KAVAclItbA.png

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

1-mDHTCaiZYCrMQa1Bry8bIQ (1).png

但是爲了儘量提高效率我們需要設置一個自定義的快捷方式。爲此找到到Preferences → Keymap,搜索Split Vertically。然後打開一個上下文菜單,點擊Add Keyboard Shortcut。

我的分屏(vertical)快捷鍵設置的是control + alt + v。做法如下面的gif圖所示。同樣的你還可以爲 horizontal split設置快捷鍵。

Untitled.gif

5. 無干擾模式

你可以到View → Enter Distraction Free Mode裏啓用它

1-RcKWZn7Ym0-L5qLQ64gbEQ.png

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

35612954-ED57-4039-9DC3-6B523C03002B.png

6. 使用Live Templates

  • 你可以使用快捷鍵:cmd + j (Windows / Linux: ctrl + j)。

    1-i9J_lzW8UpYboUojHoP-gA.gif

  • 可以使用已經定義好了的Live Templates,比如Toasts 或者if語句。

    1-vEU1cN9zT6sKDR5k_jJplg.gif

    1-XZoSS6csQ2OAhNrdpILgmw (1).gif

  • 可以使用自定義的templates。這裏是Reto Meier的一篇不錯的參考文章。你也可以參考IntelliJ IDEA的文檔。

快捷鍵以及有用的命令

1.  最有用的命令是搜索命令的命令:cmd + shift + a (Windows / Linux: ctrl + shift + a)。

假設你想關閉當前tab卻不知道怎麼做,你只需輸入close你就可以得到一個正確的快捷鍵/命令。

2. 選擇最近的複製粘貼(管理剪切版):cmd + shift + v (Windows / Linux: ctrl + shift + v)。

默認有5個最近的複製/粘貼元素。

1-VGHdyecozNSSnrOZfaIiYQ.png

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. 啓用多光標功能:control + g (alt + j for Windows / Linux)。

1-aE4ar0IEoPWuK5A_h2ir8g.gif

Bartek Lipinski在Medium上提供了一篇關於這個功能的詳細文章。強烈推薦!

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. 跳到實現:cmd + option + b (Windows / Linux: 
ctrl + alt + b)。

假如你有一個interface。通過點擊接口的名字,然後按下快捷鍵就可以跳轉到這個接口的實現。如果有多個實現會出現下拉選擇。

8. 跳轉到定義:cmd + b (Windows / Linux: ctrl + b)。

可以讓你快速跳轉到一個類,方法或者變量被定義的地方。

9. 跳轉到類型定義處:control + shift + b (Windows / Linux: 
ctrl + shift + b)。

假設你定義了:

Employee employee = new Employee(“Michal”);

當你的插入符號在employee上,這時你按下快捷鍵,你將跳轉到Employee類中。

10. 跳轉到super: cmd + u (Windows / Linux: ctrl + u)。

比如,你重寫了一些方法,當你的插入符號在方法名上,按下這個快捷鍵你將跳轉到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. 關閉當前的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. 實現接口的方法: control + i (Windows / Linux: ctrl + i)。

假設你要實現一個接口。這個快捷鍵可以讓你快速導入這個接口的所有方法。

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)。光標必須在這個文字之上時才能使用這個快捷鍵。看下面的gif圖: 

1-IJsZ53P8n9n-fO55C88-bg.gif

插件

  1. Key promoter - 快捷鍵提示插件 當你點擊鼠標一個功能的時候,可以提示 你這個功能快捷鍵是什麼 ,和這個按鈕你的使用頻率 

  2. String Manipulation - a plugin which provides actions for text manipulation (e.g. toggling styles like camelCase, hyphen-lowercase etc., capitalize text and many more).

  3. Android Material Design Icon Generator -這個插件幫助你爲工程添加Material Design圖標。安裝之後使用快捷鍵cmd + shift + m生成一個圖標。

  4. ButterKnifeZelezny - 一鍵從 佈局文件中 生成對於的 View 聲明和 ButterKnife 註解:

    20160705154501976.gif

  5. IntelliJ/Android Studio Plugin for Android Parcelable boilerplate code generation - 一個根據類的成員生成Parcelable的插件。

  6. ADB Idea - 一個幫助你使用adb命令的插件:卸載,殺死,啓動,重啓,清除數據等命令。

  7. Genymotion plugin - 一個讓你可以在Android Studio中創建和開啓Genymotion虛擬設備的插件。

  8. Android Methods Count - a plugin that parses your Android library dependencies and shows the methods count as an handy hint.

  9. Git Flow Integration - a plugin for introducing a Git Flow branching model.

  10. Builder plugin - a plugin (from Square) that generates a static nested Builder for a class.

  11. CodeGlance 代碼小窗口,可快速查看代碼



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章