The TODO Tool Window
待辦事項工具窗口
TODO means, of course, to do. TODOs are essentially comments that indicate to the?programmers and their collaborators that there remains work yet to be done. TODOs are?written like comments, beginning with two forward slashes, the word TODO in all-caps, and?a space. For example:
TODO的意思當(dāng)然就是to do疙赠。TODO對程序員來說是非常重要的筒占,說明他們的合作伙伴留下的還沒做完的工作弓候。TODO寫出來就像注釋一樣蠢甲,開始是兩個斜杠虫蝶,還有單詞TODO担神,再加一個空格怕磨。例如下面這樣:
//TODO inflate the layout here.
Create a TODO in MainActivity.java and open the TODO tool window to view it. Clicking a?TODO in the TODO tool window immediately jumps to that TODO in your source code.
在MainActivity.java文件中創(chuàng)建一個TODO,打開TODO工具窗口查看置尔。在TODO工具窗口中點擊TODO杠步,立刻在你的代碼資源中跳出來一個TODO。
The Commander Tool Window
Commander工具窗口
The Commander tool window is a navigation aid with left and right panes. These panes?function much like the Project and Structure tool windows do. The Commander tool window?differs from these other navigation windows in that it displays only one directory level at a?time, rather than displaying nested directory trees. If you prefer Windows-style navigation or?you find that the Project tool window is too overwhelming, then the Commander tool window?may be a good navigation alternative.
Commander工具窗口是一個航標撰洗,位于面板的左右兩側(cè)篮愉。這些面板功能非常像Project和Structure工具窗口。Commander工具窗口不同于其它的導(dǎo)航窗口一次只能顯示一個目錄級差导,它可以顯示目錄樹。如果你更喜歡窗口風(fēng)格的操作猪勇,或者你發(fā)現(xiàn)工程工具窗口顯示內(nèi)容太多了设褐,Commander工具窗口可能是一個好的操作選擇。
The Main Menu Bar
主菜單工具欄
The main menu bar is the uppermost bar in Android Studio, and you can execute virtually?any action by navigating through its menus and submenus. Unlike the other bars in Android?Studio, the main menu bar cannot be hidden. Don’t be overwhelmed by the many actions?contained in the main menu bar and its submenus. Even the most seasoned Android?developer will use only a fraction of these actions on a daily basis, and most of the actions?have corresponding keyboard shortcuts and/or context menu items. We discuss many of the?actions contained in the main menu bar in subsequent sections and chapters.
在Android S Studio中泣刹,主菜單工具欄是最重要的工具欄助析。你可以實際操作它的菜單和子菜單。不像在Android Studio中的其它菜單欄椅您,主菜單欄是不能被隱藏的外冀。不要被主菜單和子菜單包含的很多操作給壓倒。設(shè)置經(jīng)驗豐富的Android開發(fā)者每天都會使用這些功能掀泳,大多數(shù)的操作都有相應(yīng)的快捷鍵或者是快捷菜單雪隧。在之后的部分和章節(jié)中我們會討論很多包括主菜單欄在內(nèi)的很多操作西轩。
The Toolbar
工具欄
The toolbar contains buttons for frequently used text operations such as Cut, Copy, Paste,?Undo and Redo. As you’ve already seen in Chapter 1, the toolbar also contains buttons to?various managers within Android Studio, including the SDK Manager and the Android Virtual?Device Manager. The toolbar also has buttons for Settings and Help, as well as buttons to?Run and Debug your app. All of the buttons in the toolbar have corresponding menu items?and keyboard shortcuts. Advanced users may want to hide the toolbar to conserve screen?real-estate by unchecking the View ? Toolbar menu item.
工具欄包含很多比較常用的按鈕,比如cut(剪切)脑沿、copy(復(fù)制)藕畔、Paste(粘貼)、undo(撤銷)庄拇、redo(恢復(fù))注服。就像你已經(jīng)在第一章中看到的一樣,工具按鈕也包含Android Studio中的很多的管理器措近,包括SDK管理器和Android虛擬設(shè)備管理器溶弟。工具欄也有setting(設(shè)置)和Help(幫助)按鈕,還有兩個按鈕是用來控制你的app的:Run(運行)瞭郑、Debug(調(diào)試)辜御。所有在工具欄中按鈕都有相應(yīng)的菜單項和快捷鍵。高級用戶可能想要隱藏工具欄來保證實際屏幕的使用面積足夠大凰浮。這個操作通過取消View->Toolbar菜單項我抠。
The Navigation Bar
導(dǎo)航欄
The navigation bar displays a horizontal chain of arrow boxes representing the path from?your project’s root directory (on the left) to the currently selected tab in the Editor (on the?right). The navigation bar may be used to navigate your project’s assets without having to?resort to the Project or Commander tool windows.
導(dǎo)航欄是一個水平鏈條,顯示了你的工程的根目錄(在左邊)到你當(dāng)前被選中的頁面(在右邊)的路徑袜茧。導(dǎo)航欄不需要依靠Project tool windows或者commander tool windows就可以被用來導(dǎo)航工程信息
The Status Bar
狀態(tài)欄
The status bar, shown in Figure 2-5 (and previously in Figure 2-1), displays relevant and?context-sensitive feedback, such as information about any running processes or the state of?your project’s Git repository. Let’s explore the status bar in some detail now.
如圖2-5所示菜拓,就是狀態(tài)欄,顯示了相關(guān)的和上下文敏感的反饋笛厦,比如運行過程的信息或者是你的工程的git庫的狀態(tài)纳鼎。讓我們現(xiàn)在了解下狀態(tài)欄的一些細節(jié)。
In the leftmost corner of the status bar is the Toggle Margins button. Clicking this button?toggles hiding and showing the margins. In addition, when you hover your mouse over this?button, a context menu appears that allows you to activate any of the tool windows.?
在狀態(tài)欄最左邊角落里的是Toggle Margin按鈕裳凸。點擊這個按鈕就會顯示或者隱藏編輯器的邊界贱鄙。除此之外,把你的鼠標放在這按鈕周圍姨谷,一個快捷菜單就會出現(xiàn)逗宁,允許你激活任何工具窗口。
The message area is used to provide feedback and display any information about concurrently?running processes. This area also displays hints as you roll your mouse over UI elements?such as menu items or buttons in the toolbar. Clicking on this area opens the Event log.?The Editor cursor position displays the location of your cursor in the Editor in line:column?format. Clicking on this area activates a dialog box allowing you to navigate directly to a?particular line in your code.
信息域可以提供反饋和顯示一些關(guān)于正在運行的進程的信息梦湘。當(dāng)你在UI元素周圍滾動你的鼠標的時候瞎颗,這個區(qū)域也顯示一些提示,比如工具欄中的菜單項捌议。點擊這片區(qū)域會打開Event log(事件日志)哼拔。編輯器光標的位置顯示了你的光標在編輯器中行和列的位置。點擊這片區(qū)域打開一個對話框瓣颅,這個對話框允許你直接導(dǎo)航到你的代碼的具體某一行倦逐。
The line separator area displays the format of the carriage returns used in your text files.?On Windows, the default is CRLF, which stands for carriage return line feed. LF is the?standard format used on Unix and Mac machines, as well as in Git. If you’re developing on a?Windows computer, Git will typically convert from CRLF to LF when committing your code to?the repository.
行分隔符顯示了在你的文本文件中回車的使用方式。在windows中宫补,默認就是回車換行符檬姥,這代表了回車換行曾我。LF(換行)是使用在Unix和Mac還有Git中的標準形式。如果你在windows環(huán)境中開發(fā)穿铆,當(dāng)你要提交你的代碼到代碼庫的時候您单,Git通常是將回車換行轉(zhuǎn)換成換行。
The text format area describes the text encoding used for your source files. The default is?UTF-8, which is a superset of ASCII and includes most of the Western alphabets, including?any characters that you might find in a standard Java or XML file.
文本格式域描述了你的文件的文本編碼方式荞雏。默認的編碼方式是UTF-8虐秦。UTF-8是ASCII碼的一個超集,它包含了大多數(shù)的西方的文字凤优,這其中含有一些你可能在標準Java或者XML發(fā)現(xiàn)的字母悦陋。
The file access indicator area allows you to toggle between read/write and read-only. An?unlocked icon means that the current file in the Editor has read/write access. A lock icon?means that the current file in the Editor is read-only. You can toggle these settings by?clicking the indicator’s icon.
文件訪問指示器允許你在讀/寫和只讀之間進行切換。一個開鎖的標志意味著編輯器中的當(dāng)前文件有讀/寫權(quán)限筑辨。一個鎖的標志的意思是當(dāng)卡你的文件只有讀的權(quán)限俺驶。你可以通過點擊指示器的圖標來進行自由設(shè)置。
The Highlighting Level button activates a dialog box with a slider that allows you to set the?level of highlighting you want to see in your code.?The default setting is Inspections, which corresponds to an icon of a frowning Inspections?Manager. This setting indicates that you should be prepared for some tough love, as the?Inspections Manager will be strict in identifying both syntax errors and possible problems?with your code, called warnings. You can see some of the warnings generated by the?Inspections Manager in the marker bar as yellow ticks.
高亮水平按鈕激活了一個帶著滑動條的對話框棍辕,這回允許你設(shè)置你的代碼的語法高亮的水平暮现。默認的設(shè)置是Inspection(檢查),對應(yīng)的是一個褶皺的圖標楚昭,意思是Inspections Manager(檢查管理器)栖袋。這個設(shè)置表預(yù)示著你應(yīng)該會很喜歡這個,因為Inspection Manager將會對你的代碼中可能出現(xiàn)的問題和語法錯誤進行非常嚴格的檢查抚太,我們叫它作警告塘幅。你可以在標記欄中看到由Inspection Manager收集起來的黃色標識的警告信息。
The next setting on the slider is Syntax, which corresponds to an icon of the Inspections?Manager in profile. For this setting, the Inspections Manager is turning a blind eye to?warnings. Syntax mode is less strict than Inspections mode, but still highlights problems?with syntax that will prevent your code from compiling.
在滑動器中的下一個設(shè)置是Syntax(語法)尿贫,對應(yīng)著屬性中的Inspection Manager的一個圖標电媳。有了這個設(shè)置,Inspection Manager就會無視警告信息庆亡。Syntax模式并沒有Inspection模式嚴謹匾乓,但是仍然會對阻礙你代碼成功編譯的語法問題進行高亮提示。
The last highlight mode on the slider is None, which corresponds to an icon of a smiling?Inspections Manager. This icon makes me think that the Inspections Manager is happy-drunk?and just doesn’t care about your code. Even the most egregious syntax errors are ignored?in this mode, though the compiler will still choke on them when you attempt to build.?I recommend leaving the highlight level to Inspections and learning to appreciate the?Inspections Manager’s tough love.
在滑動器中的最新的高亮模式是None(空)又谋,對應(yīng)著一個微笑的Inspection Manager圖標钝尸。這個圖標會讓我們聯(lián)想到Inspection Manager在快樂的飲酒,根本不關(guān)心的代碼問題搂根。在這種模式下,甚至最可惡的語法錯誤都會被忽略铃辖。盡管當(dāng)你試圖創(chuàng)建它們的時候?qū)?dǎo)致編譯錯誤剩愧。我建議設(shè)置為Inspection,然后試著去喜歡上Inspection Manager娇斩。
Common Operations
常見的操作
This section reviews various common operations used in Android Studio. If you’ve used?a text editor like Microsoft Word, you will likely be familiar with the features covered in?this section.
這一部分會帶你復(fù)習(xí)在Android Studio中的常見操作仁卷。如果你使用類似于Word的文本編輯器穴翩,你將會對這部分的內(nèi)容非常熟悉。
Selecting Text
選擇文本
As you would expect from any good text editor, double-clicking any word in a source file?selects it. In addition, clicking and dragging the cursor across letters or words selects those?text elements. Placing your cursor anywhere in a source file and pressing Shift+Down-Arrow?or Shift+Up-Arrow selects lines of text beginning at the cursor. Triple-clicking anywhere on a?line of text selects the entire line. Pressing Ctrl+A | Cmd+A selects all text in a file.
就像你期望的一款好用的文本編輯器一樣锦积,雙擊資源文件中的任何單詞就是選中了這整個單詞芒帕。除此之外,單擊并拖動你已經(jīng)選中的文本丰介。將你的光標放置在文件中的任意位置背蟆,按住shiift+向下箭頭或者shift+向上箭頭來選擇文本在光標中的開始行。在文件的某一行三擊鼠標就會選中這一行哮幢。按ctrl+A|cmd+A全選文本內(nèi)容带膀。
If you place your cursor inside any word and press Ctrl+W | Alt+Up-Arrow, the entire word?becomes selected. If you continue to press Ctrl+W | Alt+Up-Arrow, the selection grows to?include adjacent text ad infinitum. If you now press Ctrl+Shift+W | Alt+Down-Arrow, the?selection shrinks. This growing/shrinking selection functionality is called structural selection?in Android Studio.
如果你將你的光標放置在任意一個單詞的中間然后按ctrl+W|alt+向上箭頭,這整個單詞就被選中了橙垢。如果你繼續(xù)按ctrl+W|alt+向上箭頭垛叨,選中的內(nèi)容就會增長到臨近的文本,并且是無限增長的柜某。如果你按ctrl+shift+W|alt+向下的箭頭選中就會被收起嗽元。這個伸展/收縮的選擇功能在Android Studio中就被叫做Structural selection。
Using Undo and Redo
使用撤銷和恢復(fù)
The Undo and Redo commands are useful for rolling back and rolling forward a limited?number of edit operations. Changes are delimited by specific UI events such as pressing?Enter or repositioning the cursor. The keyboard shortcuts for Undo and Redo are Ctrl+Z?| Cmd+Z and Ctrl+Shift+Z | Cmd+Shift+Z, respectively. There are purple right- and leftarrows?on the left side of the toolbar that will do the same. The default on Android Studio is?to remember all your steps back to your last save or up to 300 steps. Undo and Redo are?applied to only one file at a time, so the most effective way to roll back changes is to use Git,?which is discussed in Chapter 7.
撤銷和恢復(fù)操作對于在編輯操作數(shù)量受限的情況下進行回滾和前滾是非常有用的喂击。變化是被特定的UI事件分隔開了剂癌,比如按回車或者移動光標。撤銷和恢復(fù)的快捷鍵分別是ctrl+z|cmd+z和ctrl+shift+z|cmd+shift+z惭等。在工具欄左側(cè)的紫色向右或者向左箭頭也可以完成同樣的操作珍手。在Android Studio中默認的是記住你直到你最近保存的所有的操作或者最高記住300步操作。撤銷和恢復(fù)在同一時刻只能應(yīng)用于一個文件辞做,因此最有效的回滾方式就是使用Git琳要,這個我們會在第七章討論。
Finding Recent Files
尋找最近使用的文件
Among the best features of Android Studio is that it remembers all the files you worked on?recently. To activate this command, choose View ? Recent Files or press Ctrl+E | Cmd+E.?The resulting dialog box allows you to select any recent file and opens it as a tab in the?Editor. The default limit remembers up to 50 previous files. You can change these limits by?navigating to File ? Settings ? Limits ? Editor ? Recent Files Limit.
Android Studio中所有的最好的特點就是記住你最近使用的所有文件秤茅。為了激活這個功能稚补,選擇View->Recent Files或者按Ctrl + E|Cmd+E。彈出來的結(jié)果對話框允許你選擇任何最近的文件框喳,你可以在編輯器中打開它课幕。默認的能記憶的文件個數(shù)的上限是50個。你可以通過下面的操作設(shè)置這個上限:File->Settings->Limits->Editor->Recent?Files Limit五垮。?
Traversing Recent Navigation Operations
遍歷最近的導(dǎo)航操作
Android Studio also remembers your recent navigation operations. Navigation operations?include cursor moves, tab changes, and file activations. To traverse your navigation?operations history, press Ctrl+Alt+Left-Arrow | Cmd+Alt+Left-Arrow or Ctrl+Alt+Right-Arrow?| Cmd+Alt+Right-Arrow. Keep in mind that navigation operations are different from edit?operations; if you want to traverse your edit operations, you should use Undo and Redo.
Android Studio也記住了你最近的導(dǎo)航操作乍惊。導(dǎo)航操作包括你的鼠標移動,標簽變化放仗,文件激活润绎。為了遍歷你的導(dǎo)航操作的歷史,Ctrl+Alt+左箭頭|Cmd+Alt+左箭頭或者Ctrl+Alt+右箭頭|Cmd+Alt+右箭頭。記住導(dǎo)航操作跟編輯操作不同莉撇。如果你想要遍歷你的編輯操作呢蛤,你應(yīng)該使用撤銷和恢復(fù)
Cutting, Copying, and Pasting
剪切、復(fù)制和粘貼
If you’ve used any text editor or word processor, you’re familiar with Cut, Copy, and?Paste. Table 2-2 lists these basic commands, as well as some of the extended clipboard?commands.
如果你用過一些文本編輯器或者文字處理器棍郎,你對這三個功能是十分熟悉的其障。表2-2列出了基本的命令,還有一些擴展的剪切板命令涂佃。
Table 2-2. Cut, Copy, and Paste
Command ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? PC Keys ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Mac Keys
Cut ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Ctrl+X ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+X
Copy ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+C ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+C
Paste ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+V ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+V
Extended Paste ? ? ? ? ? ? ? ? ? ? Ctrl+Shift+V ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+Shift+V
Copy Path ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+Shift+C ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+Shift+C
Copy Reference ? ? ? ? ? ? ? ? ? Ctrl+Alt+Shift+C ? ? ? ? ? ? ? ? ? ?Cmd+Alt+Shift+C
In addition to the simple Cut, Copy, and Paste functionality provided by the OS clipboard,?Android Studio has an extended clipboard that remembers the last five Cut and Copy?operations. When you cut or copy text from Android Studio—or virtually any other?application while Android Studio is running—Android Studio places that text onto a stack.?To see the extended clipboard stack, press Ctrl+Shift+V | Cmd+Shift+V. The resulting dialog?box allows you to choose whichever item you’d like to paste. See Figure 2-6.
除了操作系統(tǒng)提供的剪切励翼、復(fù)制和粘貼功能,Android Studio也有擴展的剪切板功能巡李,一共能記住最近五次的剪切和復(fù)制操作抚笔。當(dāng)你從Android Studio中剪切或者復(fù)制文本時------或者實際上當(dāng)Android Studio運行的時候其它的應(yīng)用——Android Studio會將文本放進一個堆。為了看到這個擴展的剪切板的堆侨拦,按Ctrl+Shift+V|Cmd+Shift+V殊橙。結(jié)果對話框允許你選擇任何你想要粘貼的內(nèi)容。如圖2-6:
You can also change the size of the extended clipboard stack by navigating to File ??Settings ? Limits ? Editor ? Maximum Number of Contents to Keep in Clipboard. You?can also compare any currently selected text with that of the most recent element in the?extended clipboard by right-clicking the selection and selecting the Compare with Clipboard?menu item.
你也可以自己設(shè)置擴展的剪切板堆的大杏印:File->Setting->Limits->Editor->Maximum?Number of Contents to Keep in Clipboard膨蛮。你也可以在剪切板菜單項中選擇Compare來將當(dāng)前被選中的文本和擴展剪切板中內(nèi)容進行對比,這個操作通過右擊選中內(nèi)容完成季研。
The Copy Path command Ctrl+Shift+C | Cmd+Shift+C copies the fully qualified operating?system path of any file or directory selected in the Project or Commander tool windows, or?any tab of the Editor. Copy Path is particularly useful for operations in a terminal session.
復(fù)制路徑命令Ctrl+Shift+C|Cmd+Shift+C復(fù)制了在工程或者命令工具窗口或編輯器某一頁中被選中的任何文件或目錄的絕對路徑敞葛。Copy Path操作在終端中的操作尤其有用。
With Copy Reference Ctrl+Alt+Shift+C | Cmd+Alt+Shift+C, Android Studio allows you to?copy a logical reference to a method, variable, or class. When you paste this reference into?another source file, Android Studio automatically includes any required package qualifiers?and imports. You can also use generic Cut, Copy, and Paste on packages, directories, and?files in the Project and Commander tool windows in lieu of mouse operations such as?drag-and-drop in order to reorganize the location of assets in your project.
使用復(fù)制索引操作Ctrl+Alt+Shift+C|Cmd+Alt+Shift+C与涡,Android Studio允許你復(fù)制一個邏輯索引到一個方法惹谐,變量,或者一個類驼卖。當(dāng)你復(fù)制這個索引到另外一個文件的時候氨肌,Android Studio會自動導(dǎo)入所需要的包和入口。你也可以使用通用的剪切酌畜、復(fù)制和粘貼在工程和Commander工具窗口的包怎囚、目錄和文件上,這是為了代替鼠標操作桥胞,比如通過拖放操作來重新組織你的工程中的文件
Context Menus
快捷菜單
Numerous context menus can be activated by right-clicking (Ctrl-clicking on Mac) on the?IDE. You’ve already explored the Editor tab context menu in a previous section. Most panes,?icons, and bars in Android Studio will generate a context menu if you right-click (Ctrl-click?on Mac) it. One of the greatest features of Android Studio is that actions may be performed?in more than one way. This redundancy means that you are free to develop your skills and?habits according to your own preferences. I find that using keyboard shortcuts for the most?frequent operations, and menu and context-menu actions for less-frequent operations is?the most effective way to interface with Android Studio. Explore the context menus by rightclicking?(Ctrl-clicking on Mac) bars, tabs, panes, and files in the IDE now.
在IDE中大量的快捷菜單都可以通過右擊(Mac中是Ctrl)來激活恳守。你已經(jīng)在前面的部分找到了編輯器中的頁面快捷菜單。在Android Studio中的大多數(shù)的面板贩虾,視圖還有標題欄都可以通過右擊鼠標彈出來快捷菜單催烘。Android Studio中最大的一個特點就是一個操作可以通過不僅一種方式進行。這種冗余意味著你可以按照你的喜好自由的養(yǎng)成你的使用習(xí)慣缎罢。我發(fā)現(xiàn)在Android Studio中是用快捷鍵對于一些頻繁的操作和對于較少使用的菜單颗圣、快捷菜單的使用時最有效率的≡樱現(xiàn)在在你的IDE通過右擊標題欄、面板在岂、標簽和文件找到相應(yīng)的快捷菜單。
Getting Help
取得幫助
The Help menu in Android Studio has several useful menu items. Find Action (Ctrl+Shift+A?| Cmd+Shift+A) is the command you will use most often to get help in Android Studio. This?command activates a dialog box that allows you to search for any feature in Android Studio.?Press Ctrl+Shift+A | Cmd+Shift+A and type Show Line Numbers in the search box. Now?use your arrow keys to select Settings and press Enter. In the Settings window, choose?Editor ? Appearance. You should see the Show Line Numbers check box.
在Android Studio中的幫助菜單中有很多有用的菜單項蛮寂。Find action(發(fā)現(xiàn)操作)(Ctrl+Shift+A|Cmd+Shift+A)在Android?Studio中是最常使用的找到幫助的方式蔽午。這個命令激活了一個對話框,在這個對話框里你能找到一些關(guān)于Android Studio的特性酬蹋。按Ctrl+Shift+A|Cmd+Shift+A然后再查找對話框里鍵入Show Line Number(顯示行號)〖袄希現(xiàn)在使用你的方向箭頭來選擇設(shè)置然后回車。在設(shè)置窗口中范抓,選擇Editor->Appearance骄恶。你應(yīng)該看到顯示行號的對話框。
Choosing Help ? Online Documentation is your source to all the technical specifications for?Android Studio. This is the most comprehensive documentation for Android Studio. Also,?the Help ? Default Keymap Reference menu item is a useful reference. You may consider?printing this PDF and keeping it nearby as you learn to use Android Studio.
選擇Help->Online Documentation是AndroidStudio的所有技術(shù)規(guī)格的資源匕垫。這是Android Studio綜合性最強的文檔僧鲁。Help->Default Keymap Reference菜單項也是一個很有用的索引。你可以打印這個PDF象泵,當(dāng)你學(xué)習(xí)PDF的時候放在你的周圍寞秃。
Navigating with the Keyboard?
快捷鍵操作
The keyboard is perhaps the most powerful way to navigate around Android Studio.?Select the Navigate menu from the main menu bar to inspect its contents. This section?discusses the most important menu items (shown in Table 2-3) and their corresponding?keyboard shortcuts from the Navigate menu. Subsequent chapters discuss other menu items.
快捷鍵操作可能是操作Android Studio最高效的方式。從主菜單中選擇導(dǎo)航菜單來查看它的內(nèi)容偶惠。這一部分討論了最重要的菜單項(如表2-3所示)和來自導(dǎo)航菜單的相對應(yīng)的快捷鍵春寿。下一章將會討論其它的菜單項
Table 2-3. Keyboard Navigation
Command ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? PC Keys ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Mac Keys
Select In ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Alt+F1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Alt+F1
Class ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+N ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Cmd+O
File ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+Shift+N ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+Shift+O
Line ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+G ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+L
Related File ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Ctrl+Alt+Home ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Alt+Cmd+Up-Arrow
Last Edit Location ? ? ? ? ? ? ? ? ? ? ? Ctrl+Shift+Backspace ? ? ? ? ? ? ? ? ? ? ? ? ? Cmd+Shift+Backspace
Type Hierarchy ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Ctrl+H ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+H
Declaration ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+B ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+B
Select In
選擇性進入
One of the best features of Android Studio is that navigation is bilateral. You’ve already seen?how to open/activate files as tabs of the Editor from various tool windows. Now you’re going?to learn how to navigate to various tool windows from the Editor.
Android Studio最重要的一個特點是導(dǎo)航是雙邊的。你已經(jīng)了解了怎行從各種各樣的工具窗口中打開文件作為編輯器的頁面『瞿酰現(xiàn)在你要學(xué)習(xí)如何如何從編輯器的各種各樣的工具窗口中進行操作绑改。
Press Alt+F1. This activates the Select In context menu, which contains several menu items,?including Project View, Favorites, and File Structure. Click the Project View option. The?Project tool window becomes activated, the file corresponding to the active tab of the Editor?is highlighted, and any parent directories of that file are toggled open. Android projects tend?to have a lot of file assets; therefore, using Select In is among the most important skills that?you will master.
按下Alt+F1。這個打開Select In的快捷菜單兄一。它會包含很多的菜單項厘线,包括工程視圖,收藏夾瘾腰,還有文件結(jié)構(gòu)皆的。點擊Project View(工程視圖)選項。工程工具窗口就被打開了蹋盆,相應(yīng)的文件編輯器的頁面就會亮起來费薄。一些文件的父目錄也會被打開。Android工程有很多的文件栖雾;因此楞抡,使用Select In是你要掌握的最重要的技能。
Class
類
The Class action allows you to navigate to a particular Java class. It’s important to note that?this action searches for only Java source files, or inner classes of Java source files. Press?Ctrl+N | Cmd+O and start typing act. Android Studio has already indexed all of your files,?and so it will provide you a list of possible matches, with the most likely match highlighted.?All you need to do is press Enter to open MainActivity.java.
Class(類)操作允許你操作Java中的某個類析藕。你需要記住的是這個操作只查找Java文件或者Java內(nèi)部類的文件召廷。按Ctrl+N|Cmd+O然后開始鍵入act(操作)。Android Studio已經(jīng)索引了你的所有文件,因此將會提供給你一個可能匹配的清單竞慢,最有可能匹配的將會有高亮顯示先紫。你所要做的就是按回車打開MainActivity.java。
File
文件
The File action allows you to navigate to any file in your project. If you’re looking for an?XML file in your project, this is the action that you will want to use. Press Ctrl+Shift+N |?Cmd+Shift+O and start typing act. We’ve used the same search term act on purpose to?illustrate the wider scope of Navigate ? File. Notice that the search results include the Java?source file MainActivity.java as well as any other files, such as activity_main.xml. Use the?arrow keys to select activity_main.xml and press Enter to open it.
文件操作允許你找到你工程中的任何文件筹煮。如果你正在你的工程中查找XML文件遮精,這個操作可能就是你想要的。按Ctrl+Shift+N|Cmd+Shift+O然后開始鍵入操作(act)败潦。我們使用同一個查找單詞act就是為了說明Navigate->File的范圍是比較寬泛的本冲。注意到查找結(jié)果包括MainActivity.java還有其它的文件,比如activity_main.xml文件劫扒。使用方向箭頭來選擇activity_main.xml然后按回車打開它檬洞。
Line
行
The Line action Ctrl+G | Cmd+L activates a dialog box that allows you to navigate to a?particular line:column of your source file. If you type a simple integer in the resulting Go to?Line dialog box and press OK, Android Studio will jump to that line without regard to column.
行操作Ctrl+G|Cmd+L激活了一個對話框,在這個對話框中可以允許你操作你的文件的某一行沟饥。如果你在對話框Go to Line中鍵入一個簡單的整數(shù)添怔,然后按OK,Android Studio將會不考慮列調(diào)到那一行闷板。
Related File
相關(guān)文件
The Related File action Ctrl+Alt+Home | Alt+Cmd+Up-Arrow is one of the most useful?commands in Android Studio. Android projects typically have a lot of related files. For?example, a simple Android activity usually has at least one corresponding XML layout file?that renders the activity’s layout, and one corresponding XML menu file that renders the?activity’s menu. As you work with fragments, this complexity only increases. You’ve already?seen how to group related files together by using Favorites. With Navigate ? Related File,?you can query Android Studio to show you related files. With the MainActivity.java tab?activated, press Ctrl+Alt+Home | Alt+Cmd+Up-Arrow. You should see activity_main.xml?listed there. Use your arrow keys to select it and press Enter.
相關(guān)文件操作Ctrl+Alt+Home|Cmd+Alt+上箭頭是Android Studio中最有用的命令澎灸。Android工程通常會有很多的相關(guān)文件。例如遮晚,一個Android的activity通常至少有一個相關(guān)的XML布局文件來渲染activity的布局性昭,還有一個相關(guān)的XML菜單來渲染activity的菜單。就像你操作fragment县遣,這個復(fù)雜性就會增加糜颠。你已經(jīng)知道了怎樣使用Favorites來關(guān)聯(lián)整個組的文件。使用操作Navigate->Related File,你可以詢問Android Studio顯示相關(guān)聯(lián)的文件萧求。MainActivity.java標簽被激活后其兴,按Ctrl+Alt+Home|Alt+Cmd+上箭頭。你應(yīng)該看到列出了activity_main.xml文件夸政。使用你的方向鍵開選擇然后回車元旬。
菜?$?"?C?
Last Edit Location
最近的編輯位置
The Last Edit Location action Ctrl+Shift+Backspace | Cmd+Shift+Backspace allows you to?navigate to your last edit. If you continue to activate this command, your cursor will move?to the file/location of your previous edit, and so on.
Last Edit Lcation操作Ctrl+Shift+空格|Cmd+Shift+空格,這個操作允許你看到最近的編輯位置。如果你繼續(xù)激活這個命令守问,你的光標將會移動的文件之前操作的位置匀归,一直激活,光標一直移動耗帕。
Type Hierarchy
類型層次
Android uses Java, an object-oriented programming language. One of the hallmarks of any?object-oriented language is inheritance, which facilitates code reuse and polymorphism.?With the MainActivity.java file active in the Editor, press Ctrl+H to toggle open the?Hierarchy tool window. There you will see a cascading series of objects, all of which can?trace their ancestry to the progenitor of all objects in Java called Object. Keep in mind that?the Navigate ? Type Hierarchy action will work only when the active tab in the Editor is a?Java source file.
Android使用一種面向?qū)ο蟮木幊陶Z言——Java穆端。任何一種面向?qū)ο蟮淖兂烧Z言都具有的一個特點是繼承,這是為了促進代碼的重用和和多態(tài)仿便。在編輯器中打開MainActivity.java文件体啰,按Ctrl+H來打開層級工具床口攒巍。你將會看到一系列的級聯(lián)對象,所有的對象都可以追蹤它們的起源直到Java中的object對象荒勇。記住柒莉,Navigate->Type的類型層次操作只能在Java文件中進行
Declaration
聲明操作
The Declaration action allows you to jump to the original definition of methods, variables,?and resources. Another way to activate this action is by holding the Ctrl|Cmd key down while?rolling your mouse over methods, variables, or resources in your file. If the element becomes?underlined, you may navigate to its declaration by left-clicking the element while continuing?to hold down the Ctrl|Cmd key. In MainActivity.java, click your cursor anywhere in the?method setContentView(...) and press Ctrl+B | Cmd+B. You will be taken immediately to?this method’s declaration, which is located in one of MainActivity’s superclasses called?ActionBarActivity.java.
聲明操作可以允許你直接跳躍到方法、變量枕屉、資源的定義的起始位置常柄。另一個使用這個功能的方法是按住Ctrl|Cmd然后滾動鼠標。如果這個元素下面有了下劃線搀擂,繼續(xù)按住Ctrl|Cmd左擊這個元素你可以找到這個元素的聲明。在MainActivity.java中的setContentView()方法中的任意位置點擊你的鼠標卷玉,然后按Ctrl+B|Cmd+B哨颂。你就會立刻到達這個方法的聲明處。這個位置在一個叫ActionBarActivity.java的類中相种,它是MainActivity.java的一個子類威恼。
Finding and Replacing Text
查找和替換文本
Finding and replacing text is an essential part of programming, and Android Studio has?a powerful suite of tools to help you do just that. This section covers some of the most?important tools. Table 2-4 lists them for you.
查和替換文本是編程中至關(guān)重要的一部分,Android Studio中有強大的一系列工具幫助你完成這個工作寝并。這部分包含了很多重要的工具箫措。如表2-4所示:
Table 2-4. Find and Replace
Command ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?PC Keys ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Mac Keys
Find ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Ctrl+F ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Cmd+F
Find in Path ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Ctrl+Shift+F ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+Shift+F
Replace ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+R ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Cmd+R
Replace in Path ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ctrl+Shift+R ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Cmd+Shift+R
Find
查找
The Find action is used to find text occurrences within a single file. In MainActivity.java,?press Ctrl+F | Cmd+F to bring up a search bar that appears along the top of the Editor.?Type action in the search box of the search bar. You will notice that action is immediately?highlighted in yellow throughout your file. You will also notice small green ticks in the marker?bar indicating the locations of the found text. Rolling your mouse over the double rightarrows?on the find bar will display advanced search options.
查找功能被用來在單個文件中查找文本。在MainActivity.java中衬潦,按Ctrl+F|Cmd+F來呼出查找欄斤蔓,它出現(xiàn)在編輯器的頂端。在查找欄的查找對話框中鍵入具體操作镀岛,你將會注意到你的整個文件中這個操作后出現(xiàn)了黃色的高亮弦牡。你也將會發(fā)現(xiàn)在標記欄出現(xiàn)了綠色的十字表明了查找的文本的位置。將你鼠標指針放在查找欄旁邊的兩個箭頭上就會顯示優(yōu)先查找的選項
Find in Path
路徑中查找
The Find in Path action allows you to search in a much wider scope than with the Find action?described previously. You can also use regular expressions, and delimit results with?a file mask. Press Ctrl+Shift+F | Cmd+Shift+F and type hello in the search box of the search?bar along the top of the Editor. By default, the search scope in Find in Path is set to Whole?Project, though you can limit the search scope to a particular directory or module. Accept?the default of Whole Project and click the Find button. The results appear in the Find tool?window. Clicking an entry in the Find tool window immediately opens the enclosing file as?a new tab of the Editor and jumps to that occurrence.
Find in Path操作允許你在一個比Find操作更加寬泛的范圍中進行查找漂羊。你也可以使用正則表達式驾锰,使用文件遮蔽來界定查找結(jié)果。按Ctrl+Shift+F|Cmd+Shift+F之后再編輯器頂部出現(xiàn)的查找對話框中鍵入hello走越。默認的椭豫,F(xiàn)ind in Path的查找范圍是整個工程,當(dāng)然你可以設(shè)置查找的范圍是某個目錄或者是某個模塊旨指。接受默認查找整個工程然后點擊Find按鈕赏酥。這個將會出現(xiàn)在Find工具窗口,在Find工具窗口總點擊一個入口就會立即打開一個關(guān)閉的文件作為一個編輯器的新頁面淤毛,然后跳到出現(xiàn)的頁面今缚。
Replace
代替
The Replace action Ctrl+R | Cmd+R is used to replace a text occurrence in a single file, and?the functionality of Replace is a superset of Find. The safer way to replace text is to use the?Refactor ? Rename command, which we will cover later.
代替操作Ctrl+R|Cmd+R被用在一個單文件中取代一個文本。這個取代的功能是Find的一個子功能低淡。這種更加安全的取代文本的方式是這么操作的:Refactor->Rename姓言,我們之后將會講到這個瞬项。
Replace in Path
路徑替換
The Replace in Path action Ctrl+Shift+R | Cmd+Shift+R is a superset of Find in Path.?However, it’s almost always better to use Refactor ? Rename than to use Replace in Path,?so use this command with extreme caution as you could introduce errors.
路徑替換操作Ctrl+Shift+R|Cmd+Shift+R是Find in Path的一個超集。然而何荚,似乎使用Refactor->Rename總比Replace?in Path更加好用囱淋,因此使用這個命令要格外的小心,因為你可能會出現(xiàn)錯誤餐塘。
Summary
總結(jié)
In this chapter, we’ve discussed the Editor and the tool windows that cluster around the?Editor. We’ve discussed how to use the tool buttons and reposition them. We’ve also?discussed those tool windows that are used for navigation and the major UI elements of the?IDE, including the main menu bar, the toolbar, the status bar, the gutter, and the marker bar.?We’ve also discussed how to search and navigate by using menus and keyboard shortcuts,?as well as using Find and Replace. Finally, we discussed how to use the help system in?Android Studio. Most important, we’ve established a lexicon of UI elements in Android?Studio to which we will refer in subsequent chapters.