最強 Android Studio 使用小技巧和快捷鍵

轉載自:http://www.open-open.com/lib/view/open1458715872710.html

最強 Android Studio 使用小技巧和快捷鍵

寫在前面

本文翻譯自 Android Studio Tips by Philippe Breault,一共收集了62個 Android Studio 使用小技巧和快捷鍵。 根據這些小技巧的使用場景,本文將這62個小技巧分爲常用技巧(1 – 28)、編碼技巧(29 – 49)和調試技巧(50 – 62),分成三個部分。

每個小技巧都配有 gif 動圖,由於原圖在 google photo 上,加載較慢,本文全部轉存到七牛上了。

由於能力有限,翻譯過程中難免有所疏漏,如發現錯誤或問題,請在評論中提出,謝謝。

 

常用技巧

 

1. 書籤(Bookmarks)

  • 描述:這是一個很有用的功能,讓你可以在某處做個標記(書籤),方便後面再跳轉到此處。
  • 調用:Menu → Navigate → Bookmarks
  • 快捷鍵:
    • 添加/移除書籤:F3(OS X) 、F11(Windows/Linux);
    • 添加/移除書籤(帶標記):Alt + F3(OS X)、Ctrl + F11(Windows/Linux);
    • 顯示全部書籤:Cmd + F3(OS X) 、Shift + F11(Windows/Linux),顯示所有的書籤列表,並且是可以搜索的。
    • 上一個/下一個書籤:無,可以在設置中設置快捷鍵。
  • 更多:當你爲某個書籤指定了標記,你可以使用快捷鍵 Ctrl + 標記 來快速跳轉到標記處,比如輸入Ctrl + 1,跳到標記爲1的書籤處。

id="iframe_0.029779568081721663" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150450_182.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.029779568081721663',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 848px; height: 371px;">

2. 摺疊/展開代碼塊(Collapse Expand Code Block)

  • 描述:該操作提供一種方法,讓你隱藏你不關心的部分代碼,以一種較爲簡潔的格式顯示關鍵代碼。一個有意思的用法是隱藏匿名內部類的代碼,讓其看起來像一個Lambda表達式。
  • 快捷鍵:Cmd + “+”/”-“(OS X)、Ctrl + Shift + “+”/”-“(Windows/Linux);
  • 更多:可以在Settig → Editor → General → Code Folding 中設置摺疊規則。

id="iframe_0.9206421549897641" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150451_625.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9206421549897641',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 268px; height: 147px;">

3. 與分支比對(Compare With Branch (Git))

  • 描述:假如你的項目是使用git來管理的,你可以將當前文件或者文件夾與其他的分支進行比對。比較有用的是可以讓你瞭解到你與主分支有多少差別。
  • 調用:Menu → VCS → Git → Compare With Branch

id="iframe_0.13005055696703494" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150451_299.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.13005055696703494',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 570px; height: 328px;">

4. 與剪切板比對(Compare With Clipboard)

  • 描述:將當前選中的部分與剪切板上的內容進行比對。
  • 調用:右鍵選中的部分,在右鍵菜單中選擇“Compare With Clipboard”。

id="iframe_0.7915569208562374" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150452_318.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7915569208562374',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 519px; height: 265px;">

5. 上下文信息(Context Info)

  • 描述:當前作用域定義超過滾動區域,執行該操作將顯示所在的上下文信息,通常它顯示的是類名或者內部類類名或者當前所在的方法名。該操作在xml文件中同樣適用。
  • 調用:Menu → View → Context Info
  • 快捷鍵:Alt + Q (Windows/Linux)
  • 更多:個人認爲,這個功能更好的用法是快速查看當前類繼承的父類或者實現的接口。

id="iframe_0.6765498148743063" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150453_580.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6765498148743063',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 574px; height: 174px;">

6. 查找操作(Find Action)

  • 描述:輸入某個操作的名稱,快速查找,對於沒有快捷鍵的部分操作這是一個很有用的技巧。
  • 快捷鍵:Cmd +Shift + A(OS X)、Ctrl + Shift + A(Windows/Linux);
  • 更多:當某個操作是有快捷鍵的,會顯示在旁邊。

id="iframe_0.30950226122513413" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150453_203.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.30950226122513413',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 500px; height: 233px;">

7. 查找補全(Find Complection)

  • 描述:當你在一個文件中進行查找時,使用自動補全快捷鍵可以給出在當前文件中出現的建議單詞;
  • 快捷鍵:Cmd + F(OS X),Ctrl + F(Windows/Linux),輸入一些字符,然後使用自動補全;

id="iframe_0.3632896894123405" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150454_975.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.3632896894123405',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 418px; height: 268px;">

8. 隱藏所有面板(Hide All Panels)

  • 描述:切換編輯器鋪滿整個程序界面,隱藏其他的面板。再次執行該操作,將會回到隱藏前的狀態。
  • 調用:Menu → Window → Active Tool Window → Hide All Windows;
  • 快捷鍵:Cmd +Shift + F12(OS X)、Ctrl + Shift + F12(Windows/Linux);

id="iframe_0.04608636745251715" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150454_696.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.04608636745251715',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 566px; height: 387px;">

9. 高亮一切(Hightlight All the Things)

  • 描述:該操作將會高亮某個字符在當前文件中所有出現的地方。這不僅僅是簡單的匹配,實際上它會分析當前的作用域,只高亮相關的部分。
  • 調用:Menu → Edit → Find → Highlight Usages in File;
  • 定位到上一處/下一處:Menu → Edit → Find → Find Next/Previous;
  • 快捷鍵:相關快捷鍵請在菜單中查看;
  • 更多:
    • 如果高亮一個方法的returnthrow語句,將會高亮這個方法的所有出口/結束點;
    • 如果高亮某個類定義處的extendimplements語句,將會高亮繼承的或實現的方法;
    • 高亮一個import語句也會高亮使用到的地方;
    • 按下Esc可以退出高亮模式;

id="iframe_0.9501659106463194" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150455_379.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9501659106463194',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 198px; height: 184px;">

10. 回到上一個工具窗口(Jump to Last Tool Window)

  • 描述:有時候你會從某個工具窗口跳到編輯器裏面,然後又需要重新回到剛纔操作的那個工具窗,比如你查找使用情況的時,使用該操作可以在不使用鼠標的情況下跳轉到之前的工具窗口。
  • 快捷鍵:F12;

id="iframe_0.4839226680342108" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150455_991.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4839226680342108',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 495px; height: 176px;">

11. 上一個編輯位置(Last Edit Location)

  • 描述:該操作將使得你導航到上一處你改動過的地方,這與點擊工具欄上的返回箭頭回到上一個定位位置是不一樣的,該操作將會返回到上一個編輯的位置。
  • 快捷鍵: Cmd + Shift + Delete(OS X)、Ctrl + Shift + Backspace(Windows/Linux);

id="iframe_0.28918427787721157" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150456_124.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.28918427787721157',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 339px; height: 100px;">

12. 在方法和內部類之間跳轉(Move Between Methods and Inner Classes)

  • 描述:該操作讓光標在當前文件的方法或內部類的名字間跳轉。
  • 調用:Navigate → Next Method/Previous Method;
  • 快捷鍵:Ctrl + Up/Down(OS X)、Alt + Up/Down(Windows/Linux);

id="iframe_0.8558302072342485" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150456_69.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8558302072342485',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 425px; height: 414px;">

13. 定位到嵌套文件(Navigate to Nested File)

  • 描述:有時你有一堆存放在不同目錄下的同名文件,例如不同模塊下的AndroidManifest.xml文件,當你想定位到其中的一個文件,你會得到一堆搜索結果,你還得辨認哪個纔是你需要的。通過在檢索框中輸入部分路徑的前綴,並添加斜槓號,你就可以在第一次嘗試的時候就找到正確的那個。
  • 快捷鍵:Shift + Cmd + O(OS X)、Shift + Ctrl + N(Windows/Linux);

id="iframe_0.5087780642788857" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150457_6.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.5087780642788857',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 418px; height: 268px;">

14. 定位到父類(Navigate to parent)

  • 描述:如果光標是在一個繼承父類重寫的方法裏,這個操作將定位到父類實現的地方。如果光標是在類名上,則定位到父類類名。
  • Menu → Navigate → Super Class/Method
  • 快捷鍵:Cmd + U(OS X)、Ctrl + U(Windows/Linux);

id="iframe_0.4271376652177423" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150457_991.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4271376652177423',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 416px; height: 290px;">

15. 根據編號打開面板(Open a Panel by Its Number)

  • 描述:你可能已經注意到某些面板的名稱左邊有一個數字,這裏有個快捷操作可以打開它們。如果你沒看到面板的名稱,請點擊IDE的左下角的切換按鈕。
  • 快捷鍵:Cmd + 數字(OS X)、Alt + 數字(Windows/Linux);

id="iframe_0.18611858994700015" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150458_945.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.18611858994700015',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 567px; height: 387px;">

16. 在外部打開文件(Open File Externally)

  • 描述:通過這個快捷鍵,簡單地點擊Tab,就可以打開當前文件所在的位置或者該文件的任意上層路徑。
  • 快捷鍵:Cmd + 單擊Tab(OS X)、Ctrl + 點擊Tab(Windows/Linux);

id="iframe_0.7069655982777476" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150459_230.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7069655982777476',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 418px; height: 268px;">

17. 參數信息(Parameter Info)

  • 描述:這個操作將顯示和你在方法聲明處寫一樣的參數列表,當你想看某個存在的方法的參數,這是一個很有 用的操作。光標下的參數顯示爲黃色,如果沒有參數顯示黃色,意味着你的方法調用是無效的,很可能是某個參數分配不對。(例如一個浮點數賦值給了整型參 數)。如果你正在寫一個方法調用,突然離開編輯的地方,再返回的時候,輸入一個逗號,就可以重新觸發參數信息。
  • 快捷鍵:Cmd + P(OS X)、Ctrl + U(Windows/Linux);

id="iframe_0.44905465794727206" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150500_635.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.44905465794727206',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 472px; height: 195px;">

18. 快速查看定義(Quick Definition Lookup)

  • 描述:你曾經是否想查看一個方法或者類的具體實現,但是不想離開當前界面? 該操作可以幫你搞定。
  • 快捷鍵:Alt + Space / Cmd + Y(OS X)、Ctrl + Shift + I(Windows/Linux)

id="iframe_0.5822769938968122" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150500_17.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.5822769938968122',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 584px; height: 191px;">

19. 最近修改的文件(Recently Changed Files)

  • 描述:該操作類似於“最近訪問(Recents)”彈窗,會顯示最近本地修改過的文件列表,根據修改時間排列。可以輸入字符來過濾列表結果。
  • 快捷鍵:Cmd + Shift + E(OS X)、Ctrl + Shift + E(Windows/Linux)

id="iframe_0.5488364619668573" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150501_792.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.5488364619668573',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 411px; height: 365px;">

20. 最近訪問(Recents)

  • 描述:該操作可以得到一個最近訪問文件的可搜索的列表。
  • 快捷鍵:Cmd + E(OS X)、Ctrl + E(Windows/Linux)

id="iframe_0.5312937281560153" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150501_360.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.5312937281560153',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 480px; height: 300px;">

21. 相關文件(Related File)

  • 描述:該操作有助於在佈局文件和Activity/Fragment之間輕鬆跳轉。這也是一個快捷操作,在類名/佈局頂端的左側。
  • 快捷鍵:Ctrl + Cmd + Up(OS X)、Ctrl + Alt + Home(Windows/Linux)

id="iframe_0.13873140537180007" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150502_491.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.13873140537180007',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 480px; height: 206px;">

22. 返回到編輯器(Return to the Editor)

  • 描述:一大堆快捷鍵操作會把你從編輯器帶走(type hierarchy, find usages, 等等)。如果你想返回到編輯器,你有兩個選項:
    1. Esc:該操作僅僅把光標移回編輯器。
    2. Shift + Esc:該操作會關閉當前面板,然後把光標移回到編輯器。
  • 快捷鍵:
    • 返回但保留打開的面板:Esc
    • 關閉面板並返回:Shift + Esc

id="iframe_0.22542871139012277" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150502_890.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.22542871139012277',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 550px; height: 299px;">

23. Select In

  • 描述:拿着當前文件然後問你在哪裏選中該文件。恕我直言,最有用的就是在項目結構或者資源管理 器中打開該文件。每一個操作都有數字或者字母作爲前綴,可以通過這個前綴來快速跳轉。通常,我會 Alt + F1 然後 回車(Enter) 來打開項目視圖,然後 再用 Alt + F1 在OS X的Finder裏找到文件。你可以在文件中或者直接在項目視圖裏使用該操作。

  • 快捷鍵:Alt + F1;

id="iframe_0.3263401654548943" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150503_202.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.3263401654548943',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 449px; height: 337px;">

24. 擴大/縮小選擇(Extend/Shrink Selection)

  • 描述:該操作會在上下文逐漸擴大/縮小當前選擇範圍。例如,它會先選中當前變量,再選中當前語句,然後選中整個方法,縮小選擇則相反。
  • 快捷鍵:Alt + 上/下 (OS X)、Ctrl+W / Ctrl + Shift + W(Windows、Linux)

id="iframe_0.9672023220919073" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150504_890.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9672023220919073',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 357px; height: 212px;">

25. Sublime Text式的多處選擇(Sublime Text Multi Selection)

  • 描述:這個功能超級贊!該操作會識別當前選中字符串,選擇下一個同樣的字符串,並且添加一個光標。這意味着你可以在同一個文件裏擁有多個光標,你可以同時在所有光標處輸入任何東西。
  • 快捷鍵:Ctrl + G(OS X)、Alt + J(Windows、Linux)

id="iframe_0.5904447382781655" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150504_133.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.5904447382781655',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 228px; height: 146px;">

26. 文件結構彈窗(The File Structure Popup)

  • 描述:該操作可以展示當前類的大綱,並且可以快速跳轉。你還可以通過鍵盤輸入來過濾結果。這是一種很高效的方法來跳轉到指定方法。

  • 更多:
    • 你在輸入字符的時候可以用駝峯風格來過濾選項。比如輸入”oCr”會找到”onCreate”
    • 你可以通過勾選多選框來決定是否顯示匿名類。這在某些情況下很有用,比如你想直接跳轉到一個OnClickListener的onClick方法。
  • 快捷鍵:Cmd + F12(OS X)、Ctrl + F12(Windows/Linux)
  • 調用:Menu → Navigate → File Structure

id="iframe_0.8784325169399381" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150504_674.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8784325169399381',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 326px; height: 297px;">

27. 切換器(The Switcher)

  • 描述:該快捷鍵基本上就是IDE的alt+tab/cmd+tab命令。你可以用它在導航tab或者面板切換。一旦打開這個窗口,只要一直按着ctrl鍵,你可以通過對應的數字或者字母快捷鍵快速選擇。你也可以通過backspace鍵來關閉一個已選中的tab或者面板。

  • 快捷鍵:Ctrl + Tab

id="iframe_0.038415193324908614" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150505_985.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.038415193324908614',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 532px; height: 349px;">

28. 版本控制操作彈窗(VCS Operations Popup)

  • 描述:該操作會給你顯示最常用的版本控制操作。如果你的項目沒有用git等版本控制軟件進行管理,它至少會給你提供一個由IDE維護的本地歷史記錄。
  • 快捷鍵:Ctrl + V(OS X)、Alt + `(Windows/Linux)

id="iframe_0.7085674568079412" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150506_166.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7085674568079412',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 450px; height: 329px;">

 

編碼技巧

 

29. 列選擇/塊選擇(Column Selection)

  • 描述:正常選擇時,當你向下選擇時,會直接將當前行到行尾都選中,而塊選擇模式下,則是根據鼠標選中的矩形區域來選擇。
  • 調用:按住Alt,然後拖動鼠標選擇。
  • 開啓/關閉塊選擇:Menu → Edit → Column Selection Mode
  • 快捷鍵:切換塊選擇模式:Cmd + Shift + 8(OS X)、Shift + Alt + Insert(Windows/Linux);

id="iframe_0.29560501547530293" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150506_204.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.29560501547530293',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 497px; height: 137px;">

30. 語句補全(Complete Statement)

  • 描述:這個方法將會生成缺失的代碼來補全語句,常用的使用場景如下:
    • 在行末添加一個分號,即使光標不在行末;
    • 爲if、while、for 語句生成圓括號和大括號;
    • 方法聲明後,添加大括號;
  • 調用:Menu → Edit → Compelete Current Statement
  • 快捷鍵:Cmd + Shift + Enter(OS X)、Ctrl + Shift + Enter(Windows/Linux);
  • 更多:如果一個語句已經補全,當你執行該操作時,則會直接跳到下一行,即使光標不在當前行的行末。

id="iframe_0.7414457350969315" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150507_988.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7414457350969315',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 281px; height: 124px;">

31. 刪除行(Delete Line)

  • 描述:如果沒選中,則刪除光標所在行,如果選中,則會刪除選中所在的所有行。
  • 快捷鍵:Cmd + Delete(OS X)、Ctrl + Y(Windows/Linux)

id="iframe_0.24125888873822987" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150507_562.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.24125888873822987',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 265px; height: 103px;">

32. 行復制(Duplicate Line)

  • 描述:複製當前行,並粘貼到下一行,這個操作不會影響剪貼板的內容。這個命令配合移動行快捷鍵非常有用。
  • 快捷鍵:Cmd + D(OS X)、Ctrl + D(Windows/Linux)

id="iframe_0.06253810273483396" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150507_912.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.06253810273483396',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 265px; height: 103px;">

33. 編寫正則表達式(Edit Regex)

  • 描述:使用Java編寫正則表達式是一件很困難的事,主要原因是:
    • 你必須得避開反斜槓;
    • 說實話,正則很難;
    • 看第二條。

IDE能幫我們乾點啥呢?當然是一個舒服的界面來編寫和測試正則啦~ - 快捷鍵:Alt + Enter → check regexp

id="iframe_0.4916137845721096" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150508_18.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4916137845721096',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 419px; height: 170px;">

34. 使用Enter和Tab進行代碼補全的差別(Enter vs Tab for Code Completion)

  • 描述:代碼補全時,可以使用Enter或Tab來進行補全操作,但是兩者是有差別的。
  • 使用Enter時:從光標處插入補全的代碼,對原來的代碼不做任何操作。
  • 使用Tab時:從光標處插入補全的代碼,並刪除後面的代碼,直到遇到點號、圓括號、分號或空格爲止。

id="iframe_0.7034198213368654" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150508_451.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7034198213368654',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 252px; height: 123px;">

35. 提取方法(Extract Method)

  • 描述:提取一段代碼塊,生成一個新的方法。當你發現某個方法裏面過於複雜,需要將某一段代碼提取成單獨的方法時,該技巧是很有用的。
  • 調用:Menu → Refactor → Extract → Method
  • 快捷鍵:Cmd + Alt + M(OS X)、Ctrl + Alt + M(Windows/Linux);
  • 更多:在提取代碼的對話框,你可以更改方法的修飾符和參數的變量名。

id="iframe_0.7061992548406124" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150509_476.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7061992548406124',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 584px; height: 458px;">

36. 提取參數(Extract Parameter)

  • 描述:這是一個提取參數的快捷操作。當你覺得可以通過提取參數來優化某個方法的時候,這個技巧將很有用。該操作會將當前值作爲一個方法的參數,將舊的值放到方法調用的地方,作爲傳進來的參數。
  • 調用:Menu → Refactor → Extract → Parameter
  • 快捷鍵:Cmd + Alt + P(OS X)、Ctrl + Alt + P(Windows/Linux);
  • 更多:通過勾選“delegate”,可以保持舊的方法,重載生成一個新方法。

id="iframe_0.8355863899923861" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150510_31.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8355863899923861',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 474px; height: 263px;">

37. 提取變量(Extract Variable)

  • 描述:這是一個提取變量的快捷操作。當你在沒有寫變量聲明的直接寫下值的時候,這是一個很方便生成變量聲明的操作,同時還會給出一個建議的變量命名。
  • 調用:Menu → Refactor → Extract → Variable
  • 快捷鍵:Cmd + Alt + V(OS X)、Ctrl + Alt + V(Windows/Linux);
  • 更多:當你需要改變變量聲明的類型,例如使用 List 替代 ArrayList,可以按下Shift + Tab,就會顯示所有可用的變量類型。

id="iframe_0.544629002455622" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150510_949.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.544629002455622',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 368px; height: 269px;">

38. 內置(Inline)

  • 描述:當你開始對提取操作有點興奮的時候,突然覺得東西太多了,怎麼辦呢?這是一個和提取相反的操作。該操作對方法、字段、參數和變量均有效。
  • 調用:Menu → Refactor → Inline
  • 快捷鍵:Cmd + Alt + N(OS X)、Ctrl + Alt + N(Windows/Linux);

id="iframe_0.6689734691753983" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150511_721.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6689734691753983',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 495px; height: 232px;">

39. 合併行和文本(Join Lines and Literals)

  • 描述:這個操作比起在行末使勁按刪除鍵爽多了!該操作遵守格式化規則,同時:
    • 合併兩行註釋,同時移除多餘的//
    • 合併多行字符串,移除+和雙引號;
    • 合併字段的聲明和初始化賦值;
  • 快捷鍵:Ctrl + Shift + J;

id="iframe_0.5089333923533559" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150511_152.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.5089333923533559',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 365px; height: 303px;">

40. 動態模板(Live Templates)

  • 描述:動態模板是一種快速插入代碼片段的方法,使用動態模板比較有意思的是你可以使用合適的默認值將模板參數化,當你插入代碼片段時,這可以指導你完成參數。
  • 更多:如果你知道模板的縮寫,就可以不必使用快捷鍵,只需要鍵入縮寫並使用Tab鍵補全即可。
  • 快捷鍵:Cmd + J(OS X)、Ctrl + J(Windows/Linux);

id="iframe_0.12689057854004204" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150512_452.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.12689057854004204',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 456px; height: 258px;">

41. 上下移動行(Move Lines Up Down)

  • 描述:不需要複製粘貼就可以上下移動行了。
  • 快捷鍵:Alt + Shift + Up/Down;

id="iframe_0.7292888122610748" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150512_995.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7292888122610748',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 279px; height: 122px;">

42. 移動方法(Move Methods)

  • 描述:這個操作和移動行操作很類似,不過該操作是應用於整個方法的,在不需要複製、粘貼的情況下,就可以將整個方法塊移動到另一個方法的前面或後面。該操作的實際叫做“移動語句”,這意味着你可以移動任何類型的語句,你可以方便地調整字段或內部類的順序。
  • 快捷鍵:Cmd + Alt + Up/Down(OS X)、Ctrl + Shift + Up/Down(Windows/Linux);

id="iframe_0.9274276925716549" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150513_361.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9274276925716549',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 264px; height: 266px;">

43. 取反補全(Negation Completion)

  • 描述:有時你自動補全一個布爾值,然後回到該值的前面添加一個感嘆號來完成取反操作,現在通過使用輸入!代替enter完成補全操作,就可以跳過這些繁瑣的操作了。
  • 快捷鍵:代碼補全的時候,按下!即可(有時需要上下鍵選中候選項);

id="iframe_0.4739696301985532" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150513_689.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4739696301985532',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 466px; height: 254px;">

44. 後綴補全(Postfix Completion)

  • 描述:你可以認爲該操作是一種代碼補全,它會在點號之前生成代碼,而不是在點號之後。實際上你調用這個操作和正常的代碼補全操作一樣:在一個表達式之後輸入點號。

例如對一個列表進行遍歷,你可以輸入myList.for,然後按下Tab鍵,就會自動生成for循環代碼。

  • 調用: 你可以在某個表達式後面輸入點號,出現一個候選列表,在常規的代碼補全提示就可以看到一系列後綴補全關鍵字,同樣的,你也可以在Editor → Postfix Completion中看到一系列後綴補全關鍵字。

  • 常用的有後綴補全關鍵字有:

    • .for (補全foreach語句)
    • .format (使用String.format()包裹一個字符串)
    • .cast (使用類型轉化包裹一個表達式)

id="iframe_0.9073113678023219" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150514_367.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9073113678023219',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 474px; height: 136px;">

45. 重構(Refactor This)

  • 描述:該操作可以顯示所有對當前選中項可行的重構方法。這個列表可以用數字序號快速選擇。

  • 快捷鍵:Ctrl + T(OS X)、Ctrl + Alt + Shift + T(Windows/Linux)

id="iframe_0.8008935637772083" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150514_724.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8008935637772083',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 480px; height: 206px;">

46. 重命名(Rename)

  • 描述:你可以通過該操作重命名變量、字段、方法、類、包。當然了,該操作會確保重命名對上下文有意義,不會無腦替換掉所有文件中的名字;
  • 快捷鍵:Shift + F6
  • 更多:如果你忘記了這個快捷鍵,你可以使用快速修復(Quick Fix)的快捷鍵,它通常包含重命名選項。

id="iframe_0.26135524292476475" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150514_133.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.26135524292476475',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 332px; height: 177px;">

47. 分號/點 補全(Semicolon Dot Completion)

  • 描述:代碼補全這個功能太棒啦!我們大概都對以下這種情況很熟悉:開始輸入點什麼東西,接着從IDE得 到一些建議的選項,然後通過Enter或者Tab來選擇我們想要的補全代碼。其實還有另外一種方法來選擇補全的代碼:我們可以輸入一個點(.)或者一個分 號(;)。這樣就會完成補全,添加所選字符。這在結束一條語句補全或者快速鏈式調用方法的時候特別有用。
  • 注意點:如果你要代碼補全的方法需要參數,這些參數會被略過。
  • 快捷鍵:Autocomplete + “.” 或者 “;”

id="iframe_0.4066180717200041" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150515_370.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4066180717200041',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 352px; height: 177px;">

48. 包裹代碼(Surround With)

  • 描述: 該操作可以用特定代碼結構包裹住選中的代碼塊,通常是if語句,循環,try/catch語句或者runnable語句。 如果你沒有選中任何東西,該操作會包裹當前一整行。

  • 快捷鍵:Cmd + Alt + T(OS X)、Ctrl + Alt + T(Windows/Linux)

id="iframe_0.3621887897606939" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150515_83.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.3621887897606939',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 299px; height: 167px;">

49. 移除包裹代碼(Unwrap Remove)

  • 描述:該操作會移除周圍的代碼,它可能是一條if語句,一個while循環,一個try/catch語句甚至是一個runnable語句。該操作恰恰和包裹代碼(Surround With)相反。

  • 快捷鍵:Cmd + Shift + Delete(OS X)、Ctrl + Shift + Delete(Windows/Linux)

id="iframe_0.26446504960767925" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150515_237.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.26446504960767925',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 546px; height: 237px;">

 

調試技巧

 

50. 分析傳入數據流(Analyze data flow to here)

  • 描述:這個操作將會根據當前選中的變量、參數或者字段,分析出其傳遞到此處的路徑。 當你進入某段陌生的代碼,試圖明白某個參數是怎麼傳遞到此處的時候,這是一個非常有用的操作。
  • 調用:Menu → Analyze → Analyze Data Flow to Here
  • 快捷鍵:無,可以在設置中指定。
  • 相反的操作:分析傳出數據流(Analyze data flow from here),這個將會分析當前選中的變量往下傳遞的路徑,直到結束。

id="iframe_0.1344752844888717" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150516_937.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.1344752844888717',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 667px; height: 348px;">

51. 堆棧追蹤分析(Analyze Stacktrace)

  • 描述: 這個操作讀取一份堆棧追蹤信息,並且使它像logcat中那樣可以點擊。當你從bug報告中或者終端複製了一份堆棧追蹤,使用該操作可以很方便地調試。
  • 調用:Menu → Analyze → Analyze Stacktrace
  • 快捷鍵:無,可以在設置中指定。
  • 更多:通過使用“ProGuard Unscramble Plugin”插件,也可以分析混淆過的堆棧追蹤。

id="iframe_0.39466021419502795" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150517_579.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.39466021419502795',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 676px; height: 392px;">

52. 關聯調試程序(Attach Debugger)

  • 描述:隨時啓動調試程序,即使你沒有以調試模式啓動你的應用。這是一個很方便的操作,因爲你不必爲了調試程序而以調試模式重新部署你的應用。當別人正在測試應用,突然遇到一個bug而將設備交給你時,你也可以很快地進入調試模式。
  • 調用:點擊工具欄圖標或者Menu → Build → Attach to Android Process
  • 快捷鍵:無,可以在設置中指定,或者點擊工具欄對應的圖標。

id="iframe_0.6363532971590757" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150518_949.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6363532971590757',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 378px; height: 236px;">

53. 條件斷點(Conditional Breakpoints)

  • 描述:簡單說,就是當設定的條件滿足時,纔會觸發斷點。你可以基於當前範圍輸入一個java布爾表達式,並且條件輸入框內是支持代碼補全的。
  • 調用:右鍵需要填寫表達式的斷點,然後輸入布爾表達式。

id="iframe_0.5448604056145996" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150519_727.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.5448604056145996',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 514px; height: 264px;">

54. 禁用斷點(Disable Breakpoints)

  • 這個操作將使得斷點。當你有一個設置過複雜條件的斷點或者是日誌斷點,當前不需要,但是下次又不用重新創建,該操作是很方便的。
  • 調用:按住Alt,然後單擊斷點即可。

id="iframe_0.7409054178278893" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150519_877.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7409054178278893',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 365px; height: 235px;">

55. 計算表達式(Evaluate Expression)

  • 描述:這個操作可以用來查看變量的內容並且計算幾乎任何有效的java表達式。需要注意的是,如果你修改了變量的狀態,這個狀態在你恢復代碼執行後依然會保留。
  • 快捷鍵:處在斷點狀態時,光標放在變量處,按Alt + F8,即可顯示計算表達式對話框。

id="iframe_0.40566053963266313" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150520_710.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.40566053963266313',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 739px; height: 215px;">

56. 審查變量(Inspect Variable)

  • 描述:該操作可以在不打開計算表達式對話框就能審查表達式的值。
  • 快捷鍵:調試狀態下,按住Alt鍵,然後單擊表達式即可。

id="iframe_0.16181559837423265" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150521_270.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.16181559837423265',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 783px; height: 250px;">

57. 日誌斷點(Logging Breakpoints)

  • 描述:這是一種打印日誌而不是暫停的斷點,當你想打印一些日誌信息但是不想添加log代碼後重新部署項目,這是一個非常有用的操作。
  • 調用:在斷點上右鍵,取消Suspend的勾選,然後勾選上Log evaluated Expression,並在輸入框中輸入你要打印的日誌信息。

id="iframe_0.4413160171825439" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150521_513.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4413160171825439',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 601px; height: 470px;">

58. 標記對象(Mark Object)

  • 描述:當你在調試的時候,這個操作可以讓你給某個特殊的對象添加一個標籤,方便你後面很快地辨認。在調試時,當你從一堆相似的對象中查看某個對象是否和之前是一樣的,這就是一個非常有用的操作。
  • 調用:右鍵你需要標記的對象,選中Mark Object,輸入標籤;
  • 快捷鍵:選中對象時,按F3(OS X)、F11(Windows/Linux);

id="iframe_0.948506418382749" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150523_4.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.948506418382749',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 607px; height: 301px;">

59. 顯示當前運行點(Show Execution Point)

  • 描述:該操作會立刻把你的光標移回到當前debug處。

通常的情況是: 1. 你在某處觸發了斷點 2. 然後在文件中隨意瀏覽 3. 直接調用這個快捷鍵,快速返回之前逐步調試的地方。

  • 快捷鍵:(Debug時) Alt + F10;

id="iframe_0.6050221708137542" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150525_819.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6050221708137542',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 443px; height: 287px;">

60. 終止進程(Stop Process)

  • 描述:該操作會終止當前正在運行的任務。如果任務數量大於一,則顯示一個列表供你選擇。在終止調試或者中止編譯的時候特別有用!
  • 快捷鍵:Cmd + F2(OS X)、Ctrl + F2(Windows、Linux);

id="iframe_0.6090386151336133" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150526_687.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6090386151336133',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 451px; height: 265px;">

61. 臨時斷點(Temporary Breakpoints)

  • 描述:通過該操作可以添加一個斷點,這個斷點會在第一次被命中的時候自動移除。

  • 快捷鍵:Alt + 鼠標左鍵 點擊代碼左側(鼠標)、Cmd + Alt + Shift + F8(OS X)、Ctrl + Alt + Shift + F8(Windows/Linux)

id="iframe_0.8700260927435011" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150526_468.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8700260927435011',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 1px; height: 1px;">

62. 調用層級樹彈窗(The Call Hierarchy Popup)

  • 描述:該操作會給你展示 在一個方法的聲明和調用之間所有可能的路徑。

  • 快捷鍵:Ctrl + Alt + H

id="iframe_0.729738273890689" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://static.open-open.com/lib/uploadImg/20160323/20160323150527_44.gif?_=5591600%22%20style=%22border:none;max-width:981px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.729738273890689',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 451px; height: 384px;">


發佈了0 篇原創文章 · 獲贊 1 · 訪問量 9801
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章