您的位置:首頁技術文章
文章詳情頁

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

瀏覽:69日期:2022-09-27 10:58:43

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

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

視覺效果

1. Android Logcat的Material顏色主題。

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

要改變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面板的右上方點擊下拉菜單中的choose Edit filter configuration:

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

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

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

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

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

Square Java Code Styles with Android

Google Java Code Style .

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

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

4. 使用分屏提高效率

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

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

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

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

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

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

5. 無干擾模式

你可以到View → Enter Distraction Free Mode里啟用它

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

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

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

6. 使用Live Templates

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

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

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

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

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

可以使用自定義的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個最近的復制/粘貼元素。

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

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)。

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

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圖:

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

來自:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/1116/6776.html

標簽: Android
相關文章:
国产综合久久一区二区三区