Android 開發人員必知的 50 個秘訣、技巧和資源
作者撰寫本文的初衷,是為了羅列出Android Studio有用的提示、技巧、快捷方式和參考資源,將提高您的整體效率和操作性能。
顯然,還有很多優化、快捷方式等,但作者為了保持這篇文章的簡短,限制為50個,希望讀者會喜歡這篇文章!
注:本文是以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款風格特別值得一提:
您可以導入主題,如下面的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框架,而沒有任何編輯器選項卡和工具按鈕,代碼按中心對齊。
6. 使用活動模板
您可以使用快捷方式:cmd + j(Windows / Linux:ctrl + j)。
您可以使用許多已定義的模板,像Toasts 或if條件。
您可以使用自己的自定義模板。
快捷方式和有用的命令
1.最好的、最有用的命令是Search for command:cmd + shift + a (Windows / Linux:ctrl + shift + a)。
當你想關閉當前選項卡,不知道該怎么辦時,您只需鍵入:close你會得到一個正確的快捷方式/命令。
2.從最近的復制/粘貼中選擇(管理剪貼簿):
cmd + shift + v(Windows / Linux:ctrl + shift + v)。
默認情況下,最后有5個復制/粘貼項目。
剪貼板堆棧的深度在“設置”對話框的“編輯器”頁面的“限制”部分中配置。超過指定的數量時,將從列表中刪除最早的條目。 [
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)。
當在文本上使用插入符號時,必須使用快捷方式。檢查下面的gif:
如果您在全局使用該快捷方式,IDE將執行Project快速修復(Project quick fix)(顯示意圖操作和快速修復)。
23.Build and run: control + r (Windows / Linux: shift + F10)。
插件
- Key promoter ——幫助您更頻繁地使用鍵盤的插件。
- String Manipulation ——一個為文本操作提供操作的插件(例如,切換樣式,如camelCase、連字符-小寫等、大寫文本等還有很多)。
- Android Material Design Icon Generator ——此插件可幫助您將Material Design圖標設置為Android項目。安裝后,您可以使用快捷方式:cmd + shift + m以生成圖標(默認)。
- ButterKnifeZelezny ——一個簡單的插件,允許一鍵點擊創建Butterknife視圖注入。
- IntelliJ/Android Studio Plugin for Android Parcelable boilerplate code generation ——一個基于類中的字段生成Android Parcelable實現的插件。
- ADB Idea ——一個幫助和自動執行adb命令的插件:卸載、殺死、啟動、重新啟動、清除應用程序和清除應用程序數據并重新啟動它。
- Genymotion plugin ——此插件允許您從Android Studio創建和啟動 genymotion 虛擬設備。
- Android Methods Count ——一個解析您的Android庫所依賴的插件,并顯示方法計數作為方便的提示。
- Git Flow Integration ——一個用于引入 Git Flow分支模型 的插件。
- Builder plugin ——一個插件(從Square)生成一個類的靜態嵌套Builder。
資源
- Philippe Breault:《 當代Android Studio秘訣 》
- 《 鍵盤快捷方式參考 》
- Reto Meier:《 在Android Studio中你可能不知道能做的十件事 》
- Hadi Hariri:《 無鼠標驅策開發 》
- Philippe Breault:《 像老板一樣的Android Studio 》
- 《 Android Studio 專家 (Android 開發峰會 2015) 》
- Michael Evans:《 Android Studio 秘訣和技巧 》
- 《 遇見Android Studio 》
- Donn Felker:《 Android Studio——秘訣和技巧 》
- 《 用Android Studio調試你的App 》
- 《 你應該必備的插件——Reddit discussion 》
來自:http://www.androidchina.net/6370.html