本文講的是<b>49個你應該了解的Android Studio技巧、插件與資源,</b>撰寫本文的初衷,是為了羅列出Android Studio有用的提示、技巧、快捷方式和參考資源,将提高您的整體效率和操作性能。
顯然,還有很多優化、快捷方式等,但作者為了保持這篇文章的簡短,限制為49個,希望讀者會喜歡這篇文章!
注:本文是以MacOS X操作Android Studio為例,與Windows / Linux不一緻的地方已經标注,請讀者注意這一點。
可視化
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。 如下面gif圖所示。您也可以為水準分割視圖定義快捷方式。
5.無幹擾模式(Distraction Free Mode)
您可以依次點選: View → Enter Distraction Free Mode來開啟無幹擾模式。
在無幹擾模式下,編輯器占用整個IntelliJ IDEA架構,而沒有任何編輯器頁籤和工具按鈕,代碼按中心對齊。[IntelliJ Idea檢視模式]
6. 使用活動模闆
您可以使用快捷方式:cmd + j(Windows / Linux:ctrl + j)。
您可以使用許多已定義的模闆,像Toasts 或if條件。
您可以使用自己的自定義模闆。這裡是Reto Meier的一篇參考文章。您還可以參考IntelliJ IDEA文檔。
快捷方式和有用的指令
1.最好的、最有用的指令是Search for command:cmd + shift + a (Windows / Linux:ctrl + shift + a)。
當你想關閉目前頁籤,不知道該怎麼辦時,您隻需鍵入:close你會得到一個正确的快捷方式/指令。
2.從最近的複制/粘貼中選擇(管理剪貼簿):
cmd + shift + v(Windows / Linux:ctrl + shift + v)。
預設情況下,最後有5個複制/粘貼項目。
剪貼闆堆棧的深度在“設定”對話框的“編輯器”頁面的“限制”部分中配置。超過指定的數量時,将從清單中删除最早的條目。 [在IntelliJ IDEA中剪切,複制和粘貼]
3.啟用多光标(multicursor)功能:control + g(Windows / Linux:alt + j)。
有關此功能的詳細文章由Bartek Lipinski在Medium網站提供。強烈推薦!
4.Open a class: cmd + o (Windows / Linux:ctrl + n)。
5.Open any file:cmd + shift + o (Windows / Linux:ctrl + shift + n)。
6.Open symbol : cmd + option + o (Windows / Linux:alt + shift + n)。
7.Go to implementation: cmd + option + b (Windows / Linux:ctrl + alt + b)。
假設您有一個界面,通過單擊接口的名稱,然後單擊Go to implementation的快捷方式,您将被重定向到實作該接口的類。
8.Go to declaration: cmd + b (Windows / Linux:ctrl + b)。
它允許您快速檢查并轉到類、方法或變量的聲明。
9.Go to type declaration: control + shift + b(Windows / Linux:ctrl + shift + b)。
假設您如此定義:
Employee employee = new Employee(“Michal”);
當你的插入符号employee并單擊快捷方式時,将會被重定向到Employee類。
10.Go to super: cmd + u(Windows / Linux:ctrl + u)。
例如,您重寫一些方法。當你在方法名稱插入符号,并單擊轉到Go to super快捷方式,您将被重定向到父方法。
11.Move between tabs: cmd + shift + [ 或 cmd + shift + ] (Windows / Linux:alt + ← / →)。
12.Move between Design / Text tabs in layout’s view: control + shift + ← / →(Windows / Linux:alt + shift + ← / →)。
13.Close a current tab: cmd + w(Windows / Linux:ctrl + shift + a)。
14.Hide all windows: cmd + shift + F12 (Windows / Linux:ctrl + shift + F12)。
15.Minimize Android Studio instance: cmd + m(Windows / Linux:ctrl + m)。
16.Format your code: cmd + option + l (Windows / Linux:ctrl + alt + l)。
17.Auto-indent lines: control + option + i (Windows / Linux:ctrl + alt + i)。
18.Implement methods: control + i (Windows / Linux:ctrl + i)。
假設您實作了一個接口,然後隻需單擊此快捷方式,即可快速導入該界面提供的所有方法。
19.Smart code completion(按期望類型過濾方法和變量的清單):control + shift + space (Windows / Linux:ctrl + shift + space)。
20.Find: cmd + f(Windows / Linux: ctrl + f)。
21.Find and replace:cmd + r(Windows / Linux: ctrl + r)。
22.Move hardcoded strings to resources: option + return (Windows / Linux: alt + enter)。
當在文本上使用插入符号時,必須使用快捷方式。
如果您在全局使用該快捷方式,IDE将執行Project快速修複(Project quick fix)(顯示意圖操作和快速修複)。
23.Build and run: control + r (Windows / Linux: shift + F10)。
本文作者:佚名
來源:51CTO
原文标題:49個你應該了解的Android Studio技巧、插件與資源