Chapter 2 Navigating Android Studio(上)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?第二章 ?操作Android Studio

Android Studio is a windowed environment. To make the best use of limited screen real-estate,and to keep you from being overwhelmed, Android Studio displays only a small fraction of?the available windows at any given time. Some of these windows are context-sensitive and?appear only when the context is appropriate, while others remain hidden until you decide to?show them, or conversely remain visible until you decide to hide them. To take full advantage?of Android Studio, you need to understand the functions of these windows, as well as how?and when to display them. In this chapter, we’re going to show you how to manage the?windows within Android Studio.

Android Studio是一款視窗化的集成開發環境。為了充分使用實際的屏幕的面積、防止你變得抓狂,在任何時候Android Studio只在窗口顯示一部分功能。那些窗口都是上下文相關的,并且只有在當前需要的時候才會出現。其它的功能一般都是隱藏的,除非你故意將它們顯示出來。相反,你也可以故意將一些功能隱藏,只顯示其中一些功能。為了能充分的使用Android Studio,你需要理解這些窗口的意思,并且要清楚何時還有什么時候將這些窗口顯示出來。在這一章,我們會帶你學習如何管理Android Studio中的這些窗口

One of the essential functions of any integrated development environment (IDE) is navigation.Android projects are typically composed of many packages, directories, and files, and an?Android project of even modest complexity can contain hundreds of such assets. Your?productivity with Android Studio will depend in large measure on how comfortable you are?navigating within these assets and across them. In this chapter, we’re also going to show?you how to navigate in Android Studio.

集成開發環境至關重要的一個功能就是它的操作性。Android工程通常是由許多的包、目錄和文件組成的,并且一個普通的Android工程都可能包含有成百的這些東西。你使用Android Studio的生產效率在很大程度上取決于你對這些東西操作的舒適程度。在這一章,我們也會教你如何操作Android Studio。

Finally, we’ll show you how to use the help system within Android Studio. To take full?advantage of this chapter, open the HelloWorld project we created in Chapter 1. If this?project is already open in Android Studio, you’re ready to go. Please refer to Figure 2-1 as?we discuss the following navigation features.

最后,我們將會教你如何使用Android Studio內置的幫助系統。為了能學好這一章,打開我們在第一章中建立的工程——HelloWorld。如果這個工程已經在Android Studio中打開了,你就準備好開始學習這一章吧。請看圖2-1的詳細說明

Figure 2-1. Android Studio’s integrated development environment

The Editor

編輯器

The primary purpose of any IDE is to edit files. As one would expect, the window that allows?users to edit files in Android Studio is located in the center pane of the IDE. The Editor window?is unique among windows in that it is always visible and always located in the center pane.

一個IDE最重要的功能就是編輯文件。果然,在Android Studio中,用戶編輯文件的區域就在IDE的中間。編輯器的窗口總是在IDE的中間而且總是可見的。

In fact, the Editor window is such a pervasive feature of Android Studio that from here on?out, we refer to it simply as the Editor. All the other windows in Android Studio are called?tool windows and cluster in side panes (left, bottom, and right) around the Editor.

事實上,從現在開始,編輯窗口就是Android Studio的一個很普通的特點,我們指的是它作為編輯器的簡潔性。在Android Studio中所有的其它的窗口都被叫做工具窗口和工具集,它們都分布在編輯器的周圍(左邊,下邊,右邊)。

The Editor is a tabbed window, and in this respect it resembles a contemporary web browser.?When you open a file from one of the tool windows, from a keyboard shortcut, or from a?context menu, the file displays as a tab of the Editor. As you already discovered when you built?your first project, HelloWorld, the MainActivity.java and the activity_main.xml files were?automatically loaded in the Editor as tabs. Android Studio tries to anticipate which files you’re?likely to start editing, and then opens them automatically as tabs in the Editor upon completion?of the New Project Wizard. Virtually any file may be opened in the Editor, though raw image?and sound files cannot (yet) be edited from within Android Studio. You may also drag and drop?a file from a tool window onto the Editor; doing this opens the file as a tab in the Editor.?Along the top of the Editor are the Editor tabs. Along the left margin of the Editor is the gutter,?and along the right margin of the Editor is the marker bar. Let’s examine each in turn.

這個編輯器是一個分頁式的窗口,在這一方面,它就像是現在的網頁瀏覽器。當你從一個工具窗口、快捷鍵或者快捷菜單打開一個文件的時候,這個文件就會作為編輯器的一個分頁顯示出來。在你創建你的第一個工程HelloWorld的時候你已經發現了,MainActivety.java文件和activity_main.xml文件都會像網頁一樣自動加載到編輯器上。New Project Wizard一完成,Android Studio嘗試著提前去確定你可能開始編輯的文件,然后自動在編輯器中打開它,就像打開一個網頁一樣。實際上,某些文件也可能會在這個編輯器中打開,盡管在Android Studio中,原始的圖片和聲音文件不能被編輯。你也可能從工具窗口向編輯器中拖入一個文件,在編輯器中打開一個文件就像是打開了一個網頁。

?Editor Tabs

編輯器選項卡

To navigate among Editor tabs in Android Studio, use the Alt+Right-Arrow | Ctrl+Right-Arrow?or Alt+Left-Arrow | Ctrl+Left-Arrow keys. Of course, you may always select an Editor tab with?your mouse. The Editor tabs’ options are located in the main menu bar at Window ? Editor?Tabs. Any action you select from this menu applies to the currently selected tab. Roll your?mouse over the MainActivity.java tab and right-click (Ctrl-click on Mac) it. In the resulting?context menu, shown in Figure 2-2, you will notice many of the same options that you?discovered in Window ? Editor Tabs. From this context menu, select the Tabs Placement?submenu. The menu options Top, Bottom, Left, and Right allow you to move the tabs bar.Moving the tabs bar to the right or left accommodates more visible tabs, though at the?expense of screen real-estate.

為了操作Android Studio中的編輯器選項,使用Alt+方向鍵(四個方向鍵)。當然,你可以用鼠標選擇一個編輯器選項。編輯器的選項表的選項在主菜單欄:Window->Editor Tabs。你在這個菜單選中的任何選中的頁面。如圖2-2,將鼠標放在MainActivity.java頁面中,右擊鼠標,你將會發現你看到的和Windows->Editor?Tabs中是一樣。從這個快捷菜單中選中Tabs?Placement子菜單。菜單的選中有Top,Bottom,Left,Right(上下左右)四個選項允許你移動選項卡。根據你的桌面的實際使用面積來移動你的選項卡,向左或者向右移動,保證你能夠看到更多的選項卡。

Figure 2-2. Editor tab context menu

The Close and Close All actions of the Editor tab context menu are straightforward. The?Close Others action is used when you want to close all the tabs except the active tab.?The Split Vertically and Split Horizontally actions are used to subdivide your Editor into panes.?Split Vertically is particularly useful if you want to compare two files side by side. You may?split panes ad infinitum, though the utility of such nested splits quickly diminishes.?You may also drag and drop files from other windows to any pane of the Editor, or from one?pane to another. Closing the last tab of a pane causes the entire pane to disappear.

關閉和關閉編輯器所有選項的操作的快捷菜單是非常簡單的。當你想要關閉除了現用標欄之外的其它所有標欄時,關閉其它標欄的功能就可以被使用。Split Vertically(垂直分離)和Split Horizontal)y(水平分離)兩個操作可以對你的編輯器的面板進行再細分。如果你想要兩個文件并排對比起來,那么垂直分離就會非常有用。你可以對面板進行無限細分,雖然這種嵌套的功能很快就會減少。你也可以將文件從其他的窗口拖入其它編輯器的面板,或者從一個面板拖到另外一個面板。關掉最近的面板選項卡會造成整個面板都消失。

The Gutter

信息槽

The gutter is used to convey information about your code. Perhaps the most obvious feature?of the gutter is that small color swatches and image icons are displayed there alongside?corresponding lines of code that refer to those visual resources. The gutter is also used to?set breakpoints, facilitate code-folding, and display scope indicators. All of these features?are covered in more detail in subsequent sections and chapters.

信息槽是來傳遞你的代碼信息的。或許信息槽最明顯的特點就是小色卡,還有沿著代碼行邊的圖標,這些都是可以看得見的資源。信息槽也可以用來設置斷點,代碼折疊,還有作用域指示器。所有這些更加詳細的特點都在隨后的章節和后面的部分中。

The Marker Bar

標記欄

Along the right side of the Editor is the marker bar. The marker bar is used to indicate the?location of important lines in your source files. For example, the marker bar highlights?warnings and compile-time errors in your Java or XML files. The marker bar also shows you?uncommitted changes, search results, and the locations of bookmarks.

沿著編輯器的右邊的東西是標記欄。標記欄用來指出你的文件的重要行的位置。比如,在你的Java或者XML文件中,標記欄的高亮警示和編譯時間錯誤。標記欄也會顯示未提交的變化,查找結果還有書簽的位置。

The marker bar does not scroll like the gutter does; rather, the colored ticks on the marker?bar are positioned relative to the length of the file. Clicking a colored tick in the marker bar?immediately jumps you to that location in the file. Practice using the marker bar by clicking?some of its colored ticks now.

標記欄不能像信息槽一樣可以滾動。當然,在標記欄上的彩色記號位于和文件長度相關的位置。點擊在標記欄中的一個彩色記號就會立刻跳到你所要去的位置。現在開始聯系通過點擊一些彩色的記號來使用標記欄。

Tool Buttons

工具按鈕

You’ve already seen the Project tool window, displayed in the left pane by default. To see a?list of all the tool windows, choose View ? Tool Windows from the main menu bar. Now look?carefully along the left, right, and bottom margins of the IDE. There you will find tool buttons?that correspond to many of the tool windows. Notice that some of these tool buttons are also?labeled with a number, which is used in combination with the Alt (Cmd on Mac) key to toggle?that tool button’s corresponding tool window open/closed. Experiment with clicking the tool?buttons now to practice this skill. Also practice using the keyboard shortcuts Alt+1 | Cmd+1,?Alt+2 | Cmd+2, Alt+3 | Cmd+3, and so forth to toggle the tool windows open/closed.

你已經看到了工程工具窗口,它默認在面板的左邊。為了看到所有工具窗口的列表,在主菜單欄中選擇View->Tool Woindows。現在仔細的沿著IDE的左右和底部仔細查看。你會發現很多與工具窗口一致的工具按鈕。能注意到這些工具按鈕也是用數字標記的,這主要是為了能方便的使用快捷鍵來觸發工具窗口的開閉,快捷鍵是用Alt(Mac是CMD)+數字鍵。現在點擊工具按鈕來練習這項技能。也可以聯系使用鍵盤快捷鍵Alt+1|cmd+1,Alt+2|cmd+2,Alt+3|cmd+3,來開關窗口。

When a tool window is open, the corresponding tool button is dark gray, indicating that?it is depressed. Notice that the tool buttons are located in the corners of the margins.?For example, the default position of the Project tool button is in the upper corner of the left?margin, while the Favorites tool button is located by default in the lower corner of the?left margin.?Side panes (left, bottom, and right) may be shared by up to two tool windows at a time.

當一個工具窗口打開的時候,相應的工具按鈕是暗灰色的,表明它被按下去了。注意位于邊緣角落里的工具按鈕。例如,默認的工程工具按鈕在左邊的上面的角落里。,然而收藏夾工具按鈕默認在左邊的下面的角落里。在同一時間里,側面面板可能會被兩個以上的窗口共享。

To see how side panes may be shared, open both the Favorites and the Project tool?windows. Notice that the Favorites and Project tool buttons are located in opposing corners?of the same margin. Attempting to share a side pane between two tool windows whose?corresponding tool buttons are located in the same corner will not work. For example, the?Project and Structure tool windows cannot be displayed simultaneously—at least not in?Android Studio’s default configuration.

為了看到側面面板是如何共享使用的,打開收藏夾和工程工具窗口。注意到收藏夾和工程工具按鈕位于同一側的相反的角落里。嘗試著讓兩個工具窗口使用同一側的面板,這兩個工具窗口的按鈕在同一個角落是不能工作的。例如工程工具窗口和結構工具窗口時不能同時出現的,至少在Android Studio中的默認配置中是這樣的。

Default Layout

默認布局

Don’t confuse default layout in Android Studio with layouts in the Android SDK. A default?layout is a specific set of tool windows clustered around the Editor. Android Studio is?configured out-of-the-box with a default layout that shows the Project tool window in the left?pane. This is the layout displayed previously in Figure 2-1.

不要對Android Studio中的Android SDK布局感到混亂。一個默認的布局是環繞在編輯器周圍的一系列具體的工具窗口。Android Studio被設置為打開就可使用的默認布局,這個默認布局就顯示了左邊面面板的工程工具窗口。如圖2-1,這是一個預先已經顯示的布局。

Let’s examine the Window menu in the main menu bar. The first two menu items are Store?Current Layout as Default, and Restore Default Layout. The Restore Default Layout action?is typically used when the IDE becomes overcrowded, or you just want to clear the slate?and return to a familiar layout. You may also customize your default layout by opening and?closing whichever tool windows you like, resizing and/or repositioning them, and then setting?that new layout as the default by selecting Store Current Layout as Default.

讓我們測試一下在主菜單欄中的窗口菜單吧。前兩個菜單的主題默認是Store Current Layout(存儲當前布局)和Restore Default Layout(重置默認布局)。通常當IDE被擠滿的時候就會啟用Default Layout操作,或者是在你想要清理界面,回到自己熟悉的布局的時候也會啟用這個操作。你也通過打開或者關閉任何你喜歡的工具窗口來自定義你自己的默認布局。重置它們,然后設置新的布局作為默認布局,這個操作要選擇Store Current Layout Default才能完成。

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? REPOSITIONING TOOL BUTTONS

As mentioned, the Project and Structure tool-windows can’t be displayed simultaneously because theircorresponding tool-buttons are located in the same corner. However, you can move any tool-button to anycorner you want. Drag-and-drop the Structure tool button to the bottom corner of the left margin. Now, togglethe Project and Structure tool-windows open by using either the keyboard shortcuts Alt+1 | Cmd+1 andAlt+7 | Cmd+7 or by clicking their tool buttons. Because we moved their tool buttons to opposing corners,the Project and Structure tool windows may now share the same side pane and be displayed simultaneously.

就像上面提到過的一樣,Project和Structure工具窗口不能同時顯示,因為它們相應的工具按鈕位于相同的角落。然而,你可移動任何工具按鈕到任何你想要的角落。拖放Structure工具按鈕到左邊底部的角落里。現在,使用快捷鍵ALt+1|cmd +1和Alt+7|cmd+7或者點擊它們的工具按鈕來打開Project和Structure工具窗口,因為我們把它們的工具按鈕移動到了相反的角落。Project和Structure工具窗口現在可以出現在面板的同一邊而且可以同時出現了。


Navigation Tool Windows

導航工具窗口

This section discusses tool windows that are used specifically for navigation: Project,?Structure, Favorites, TODO, and Commander. Table 2-1 lists the function of each of these?navigation tool windows. Subsequent chapters cover many of the other tool windows.

這一部分我們討論對于操作的工具窗口。就像圖2-1列出來的那樣,列出了每個操作工具窗口的功能:Project,Structure,Favorities,TODO,Commander。隨后的章節會涵蓋其他的工具窗口。

Table 2-1. Navigation Tool Windows


Tool Window ? ? ? ? ? PC Keys ? ? ? ? ? ? ? ? ? ? ? Mac Keys ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Function


Project ? ? ? ? ? ? ? ? ? ? Alt+1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? Cmd+1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Allows you to navigate

Favorites ? ? ? ? ? ? ? ?Alt+2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? Cmd+2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Displays favorites, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bookmarks, and breakpoints

Structure ? ? ? ? ? ? ? Alt+7 ? ? ? ? ? ? ? ? ? ? ? ? ? ? Cmd+7 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Presents a hierarchical tree ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?of the objects or elements ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?in?the current file

Commander ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Similar to the ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Project tool window, but allows for ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? easy?management of files

TODO ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Displays a list of all the active ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TODOs in a project


The Project Tool Window

工程工具窗口

We find the Project tool window to be the most useful of navigation tool windows because?it combines wide scope with relatively easy access. To appreciate the power and scope?of the Project tool window, you may want to set the window’s mode to Project. There?are three modes; Project, Packages, and Android. By default, Android Studio will set the?mode to Android. Android and Project are the most useful modes, though the Android?mode may hide certain directories from you. The mode setting combo-box is located at?90 degrees and adjacent to the Project tool button in the upper left corner of the IDE.

我們發現工程工具窗口(Project tool window)是最有用的操作工具窗口,因為它范圍寬泛,可以輕松訪問。為了領會Project tool window的功能和范圍,你可能想要設置工程的窗口模式。主要有三個模式:Project,Package,Android。默認情況下,Android Studio會設置為Android模式。Android和Project模式是最常用的模式,盡管Android模式對你隱藏了某些目錄。這個模式設置復合框位于90度方向,挨著Project tool按鈕,在IDE的左上角。

The Project tool window provides a simple tree interface with files and nested directories?that you can toggle. The Project tool window gives you an overview of all the packages,?directories, and files in your project. If you right-click (Ctrl-click on Mac) a file in the Project?tool window, a context menu appears. There are three important menu items in this?context menu: Copy Path, File Path, and Show in Explorer. Clicking Copy Path copies the?operating system’s absolute path to this file to the clipboard. Clicking File Path displays?the path as a stack of directories, terminating with the file on top, and clicking any of these?directories opens them in the operating system. Clicking Show in Explorer shows the file in?a new window of your operating system. See Figure 2-3.

工程工具窗口提供了一個簡單的樹形文件和嵌套的目錄接口,你可以切換。工程工具窗口給了你一個你工程中的所有包,目錄和文件的視圖。如果你在Project tool window中右擊(在mac中是Ctrl)一個文件,一個快捷菜單就會出現。在這個快捷菜單中有三個重要的菜單選項:Copy Path(復制路徑),File Path(文件路徑),show in Explorer(在瀏覽器中顯示)。點擊Copy Path就會復制文件的絕對路徑到剪切板。點擊File Path就會顯示目錄的樹狀圖,頂部是文件的末尾,點開這些目錄中的任何一個都可以在操作系統中打開。點擊Show in Exploer文件就會在你的操作系統中的一個新的窗口中打開。如圖2-3:

Figure 2-3. The Project tool window

The Structure Tool Window

結構工具窗口

The Structure tool window displays a hierarchy of elements in your file. When the Editor?is displaying a Java source file such as MainActivity.java, the Structure tool window?displays a tree of elements such as fields, methods, and inner classes. When the Editor?is displaying an XML file such as activity_main.xml, the Structure tool window displays?a tree of XML elements. Clicking any element in the Structure tool window immediately?moves your cursor to that element in the Editor. The Structure tool window is particularly?useful for navigating among elements in large source files. Practice this skill by opening?the Structure tool window and navigating among the elements of both MainActivity.java?and activity_main.xml. See Figure 2-4.

結構工具窗口顯示了你的文件的層級。當編輯器顯示了一個java文件,比如是MainActivity.java,結構窗口工具(Structure tool windows)顯示了一個像域,方法,和內部類這樣的層級。當編輯器顯示了一個XML文件,比如是activity_main.xml,Structure?tool window顯示了一個XML文件的樹狀層級。點擊Structure tool windows中的任意一個元素,迅速移動光標到那個元素。Structure tool window在大量的資源文件中尤其作用巨大。操作activity_main.xml文件和MainActivity.java文件來練習這項技能。如圖2-4所示:


Figure 2-4. The Structure tool window

The Favorites Tool Window

收藏夾工具窗口

When developing a feature (or debugging a bug) in Android, you will likely create or?modify several related files. Moderately complex Android projects may contain hundreds?of individual files, so the ability to group related files is useful indeed. The Favorites tool?window contains favorites that allow you to logically group references to related files that?might otherwise be physically located in completely different parts of your project.?Make sure that both the MainActivity.java and activity_main.xml files are loaded as tabs?in the Editor. Now right-click (Ctrl-click on Mac) either tab in the Editor and select Add All?to Favorites from the context menu. In the Input New Favorites list Name field, type main?and press OK. If the Favorites tool window is not open, activate it now by toggling Alt+2?| Cmd+2. Expand the favorites item called main, and double-click one of the files listed?there in to open/activate it.

當在Android中開發一個特性(或者調試一個bug)的時候,你可能會創建或者修改很多相關聯的文件。一個規模適中的Android工程都可能包含上百個單獨的文件,因此分組處理相關聯的文件是非常有必要的。收藏夾工具窗口包含你的個人收藏,這些個人收藏允許你有條理的分組管理相關聯的文件,這些文件可能是完全不同于你在物理設備中的位置。確保MainActivity.java和activity_main.xml文件都被作為選項卡裝載到你的編輯器中。現在在編輯器中的兩個選項卡任選其一右擊(Mac中是Ctrl),然后從快捷菜單中選擇Add All to Favotites。在Input?New Favorites列出的命名域中鍵入main然后點擊OK。如果收藏夾工具窗口沒有打開,按Alt+2|cmd+2打開。展開名為main的收藏夾主題,雙擊列出的其中一個文件來打開它。

Just as the Favorites window allows you to navigate immediately to any particular file or groups?of files, bookmarks allow you to navigate immediately to any particular line in a file. Position?your cursor on any line in MainActivity.java. Now press F11 (F3 on Mac). This action creates?or removes a bookmark in any source file, including XML files. Notice both the checkmark?in the gutter and the black tick in the marker bar indicating the new bookmark. To view the?bookmark you just created, toggle open the bookmarks in the Favorites tool window.

就像收藏夾窗口允許你能比較直接的操縱某個文件或者某組文件,書簽允許你快速的操作文件的中的某一行。把你的光標放到文件MainActivity.java中的任意一行。現在按F11(Mac中是F3)。這個操作會創建或者刪除文件中的一個書簽,包括.XML文件。當增添一個新的書簽的時候,注意信息槽中的鉤形符號和在標記欄中的黑色記號。為了看見你創建的新書簽,在收藏夾工具窗口總打開書簽。


Note On a PC, if F11 does not seem to be responding, check to make sure that the F-Lock key isactivated on your keyboard.

注意:在電腦中,如果按F11沒有響應,檢查一下你的鍵盤的F鍵是不是被鎖住了。


Breakpoints are used for debugging. Unlike bookmarks, which may be set in any file, you?need to be in a Java source file in order to set a breakpoint. Open MainActivity.java and?click in the gutter next to the following line of code:?setContentView(R.layout.activity_main);?You will notice that a red circle now occupies the gutter and that the line is also highlighted?red. Breakpoints can be set only on executable lines of code; trying to set a breakpoint on?a comment line, for example, will not work. To view your newly created breakpoint, toggle?open the Breakpoints tree in the Favorites tool window. There are several more interesting?things you can do with breakpoints, and we discuss breakpoints at length in Chapter 12,?which is devoted to debugging.

斷點被用來程序調試。不像書簽,可以在任何文件中設置。斷點只能在java文件中設置。打開MainActivity.java文件,然后在代碼setContentView(R.layout.activity_main)前的信息槽中點擊,你會看到這一行的信息槽中出現了一個紅點,而且這一行都變成紅色的了。斷點僅僅能被設置在可執行代碼的那一行。為了看到你最新建立的斷點,在收藏夾共苦窗口中打開端點樹。你可以用斷點做很多有趣的事情,我們將會在12章詳細的討論斷點的問題,斷點只是用來調試程序的。


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容