50個(gè)安卓開發(fā)者應(yīng)該熟悉的Android Studio技巧和資源
本文列舉出一些可以提高整體效率的Android Studio技巧和資源。
顯然有太多太多這方面的東西,但是為了文章的簡(jiǎn)潔性,我把它限制在50個(gè)以內(nèi),希望你能喜歡!
視覺效果1. Android Logcat的Material顏色主題。
要改變Android Studio的Logcat你需要這樣做:進(jìn)入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
注意里面有幾個(gè)現(xiàn)有的主題,可以直接修改現(xiàn)有主題(不建議),或者點(diǎn)擊save as按鈕拷貝一個(gè)主題并改名為Material theme Color然后再改變每種類型log的顏色。
2. 防止當(dāng)前應(yīng)用崩潰時(shí)Logcat清除log。
在Android Monitor面板的右上方點(diǎn)擊下拉菜單中的choose Edit filter configuration:
注意是在工程界面的底部Android Monitor面板,而不是單獨(dú)的Android Monitor工具中。
3. 使用一個(gè)適合自己的代碼主題 (IntelliJ / Android Studio).
找到Preferences → Code Style → Java,在Scheme下拉菜單中你可以選擇一個(gè)代碼風(fēng)格(或者設(shè)置一個(gè)新的)。
有兩個(gè)風(fēng)格值得專門提一下:
Square Java Code Styles with Android
Google Java Code Style .
你可以按照下面gif圖中的做法導(dǎo)入主題:
4. 使用分屏提高效率
要打開這個(gè)功能,右鍵主屏幕的選項(xiàng)卡(tab)選擇 Split Vertically / Horizontally。
但是為了盡量提高效率我們需要設(shè)置一個(gè)自定義的快捷方式。為此找到到Preferences → Keymap,搜索Split Vertically。然后打開一個(gè)上下文菜單,點(diǎn)擊Add Keyboard Shortcut。
我的分屏(vertical)快捷鍵設(shè)置的是control + alt + v。做法如下面的gif圖所示。同樣的你還可以為 horizontal split設(shè)置快捷鍵。
5. 無干擾模式
你可以到View → Enter Distraction Free Mode里啟用它
在無干擾模式下,編輯器占據(jù)了整個(gè)IntelliJ IDEA窗口,沒有任何tab或者工具按鈕。代碼居中顯示。[ IntelliJ Idea Viewing Modes ]
6. 使用Live Templates
你可以使用快捷鍵:cmd + j (Windows / Linux: ctrl + j)。
可以使用已經(jīng)定義好了的Live Templates,比如Toasts 或者if語句。
可以使用自定義的templates。這里是 Reto Meier 的一篇不錯(cuò)的參考文章。你也可以參考 IntelliJ IDEA 的文檔。
快捷鍵以及有用的命令1. 最有用的命令是搜索命令的命令:cmd + shift + a (Windows / Linux: ctrl + shift + a)。
假設(shè)你想關(guān)閉當(dāng)前tab卻不知道怎么做,你只需輸入close你就可以得到一個(gè)正確的快捷鍵/命令。
2. 選擇最近的復(fù)制粘貼(管理剪切版):cmd + shift + v (Windows / Linux: ctrl + shift + v)。
默認(rèn)有5個(gè)最近的復(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)于這個(gè)功能的 詳細(xì)文章 。強(qiáng)烈推薦!
4. 打開一個(gè)類: 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. 跳到實(shí)現(xiàn):cmd + option + b (Windows / Linux:
ctrl + alt + b)。
假如你有一個(gè)interface。通過點(diǎn)擊接口的名字,然后按下快捷鍵就可以跳轉(zhuǎn)到這個(gè)接口的實(shí)現(xiàn)。如果有多個(gè)實(shí)現(xiàn)會(huì)出現(xiàn)下拉選擇。
8. 跳轉(zhuǎn)到定義:cmd + b (Windows / Linux: ctrl + b)。
可以讓你快速跳轉(zhuǎn)到一個(gè)類,方法或者變量被定義的地方。
9. 跳轉(zhuǎn)到類型定義處:control + shift + b (Windows / Linux:
ctrl + shift + b)。
假設(shè)你定義了:
Employee employee = new Employee(“Michal”);
當(dāng)你的插入符號(hào)在employee上,這時(shí)你按下快捷鍵,你將跳轉(zhuǎn)到Employee類中。
10. 跳轉(zhuǎn)到super: cmd + u (Windows / Linux: ctrl + u)。
比如,你重寫了一些方法,當(dāng)你的插入符號(hào)在方法名上,按下這個(gè)快捷鍵你將跳轉(zhuǎn)到parent的這個(gè)方法。
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. 實(shí)現(xiàn)接口的方法: control + i (Windows / Linux: ctrl + i)。
假設(shè)你要實(shí)現(xiàn)一個(gè)接口。這個(gè)快捷鍵可以讓你快速導(dǎo)入這個(gè)接口的所有方法。
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. 把一個(gè)硬編碼的字符串放到資源文件中:option + return (Windows / Linux: alt + enter)。光標(biāo)必須在這個(gè)文字之上時(shí)才能使用這個(gè)快捷鍵。看下面的gif圖:
來自:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/1116/6776.html
相關(guān)文章:
1. python爬蟲實(shí)戰(zhàn)之制作屬于自己的一個(gè)IP代理模塊2. asp批量添加修改刪除操作示例代碼3. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)財(cái)務(wù)記賬管理系統(tǒng)4. css代碼優(yōu)化的12個(gè)技巧5. 如何在jsp界面中插入圖片6. Vue element ui用戶展示頁面的實(shí)例7. Ajax返回值類型與用法實(shí)例分析8. 使用FormData進(jìn)行Ajax請(qǐng)求上傳文件的實(shí)例代碼9. .NET6打包部署到Windows Service的全過程10. HTML 絕對(duì)路徑與相對(duì)路徑概念詳細(xì)
