天天看點

Android 開發人員必知的50個秘訣、技巧和資源

作者撰寫本文的初衷,是為了羅列出android studio有用的提示、技巧、快捷方式和參考資源,将提高您的整體效率和操作性能。

顯然,還有很多優化、快捷方式等,但作者為了保持這篇文章的簡短,限制為50個,希望讀者會喜歡這篇文章!

(本文是以macos x操作android studio為例,與windows / linux不一緻的地方已經标注,請讀者注意這一點。)

一、可視化

1、android logcat的材料顔色主題(material colors theme)。

Android 開發人員必知的50個秘訣、技巧和資源

要更改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。

Android 開發人員必知的50個秘訣、技巧和資源

3、将您的ide(intellij / android studio)應用正确的代碼樣式。

依次點選preferences → code style → java,在scheme下拉清單中選擇您的代碼樣式(或設定一個新的代碼樣式)。

有2款風格特别值得一提:

square java code styles with android

google java code style

您可以導入主題,如下面的gif所示:

Android 開發人員必知的50個秘訣、技巧和資源

使用分屏可提高效率。

Android 開發人員必知的50個秘訣、技巧和資源

要打開此功能,您需要在主螢幕的頁籤上單擊滑鼠右鍵,然後選擇split vertically / horizontally 。

Android 開發人員必知的50個秘訣、技巧和資源

但為了盡可能高效,我們需要設定一個自定義鍵盤的快捷方式。要做到這一點,依次點選preferences → keymap 并找到split vertically。然後打開上下文菜單并單擊 add keyboard shortcut。

以我為例,對于垂直拆分視圖,我增加了control + alt + v。 如下面gif圖所示。您也可以為水準分割視圖定義快捷方式。

Android 開發人員必知的50個秘訣、技巧和資源

5、無幹擾模式(distraction free mode)

您可以依次點選: view → enter distraction free mode來開啟無幹擾模式。

Android 開發人員必知的50個秘訣、技巧和資源

在無幹擾模式下,編輯器占用整個intellij idea架構,而沒有任何編輯器頁籤和工具按鈕,代碼按中心對齊。[intellij idea檢視模式]

使用活動模闆

您可以使用快捷方式:cmd + j(windows / linux:ctrl + j)。

Android 開發人員必知的50個秘訣、技巧和資源

您可以使用許多已定義的模闆,像toasts 或if條件。

Android 開發人員必知的50個秘訣、技巧和資源
Android 開發人員必知的50個秘訣、技巧和資源

您可以使用自己的自定義模闆。這裡是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個複制/粘貼項目。

Android 開發人員必知的50個秘訣、技巧和資源

剪貼闆堆棧的深度在“設定”對話框的“編輯器”頁面的“限制”部分中配置。超過指定的數量時,将從清單中删除最早的條目。 [在intellij idea中剪切,複制和粘貼]

3.啟用多光标(multicursor)功能:control + g(windows / linux:alt + j)。

Android 開發人員必知的50個秘訣、技巧和資源

有關此功能的詳細文章由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快捷方式,您将被重定向到父方法。

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:

Android 開發人員必知的50個秘訣、技巧和資源

如果您在全局使用該快捷方式,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》