注:⌘(command)、⎇(option)、⌃(control)、⎋(esc)、⇧(shift)、⇪(caps lock)、⌃(control)、↩(return)、⌅(enter)

# 如何查看 "Tip of the Day"

You can always get back to it from Help | Tip of the Day main menu item.

# 快速打开任何class

press ⌘O (Naviage | Class) and start typing the name of the class. Choose the class from a drop-down list that appears. You can open any file in your project in a similar way by using ⇧⌘O (Navigate | File)

command + O

# 如何快速补全a class name

The Code Completion feature lets you quickly complete different kinds of statements in the code. For example, start typing a class name and press ⌃Space to complete it. When multiple choices are available, they are shown in the lookup list.

# 快速定位

You can quickly find all places where a particular class, method or variable is used in the whole project by positioning the caret at the symbol's name or at its usage in code and pressing ⌥F7 (Edit | Find | Find Usages in the popup menu).

# 在插入符号处快速查看类或方法

To quickly see the documentation for a class or method at caret, press F1 (View | Quick Documentation).

# 跳转到声明类

To navigate to the declaration of a class, method or variable used somewhere in the code, position the caret at the usage and press ⌘B (Navigate | Declaration). You can also click the mouse on usages with the Ctrl key pressed to jump to declarations.

# 方便的在列表中找到项目

You can quickly navigate in the currently edited file with ⌘F12 (Navigate | File Structure). It shows the list of members of the current class. Select an element you want to navigate to and press the Enter key or the ⌘↓ key. To easily locate an item in the list, just start typing its name.

# 快速重命名类、方法、变量,并自动更正所有使用它的位置

You can easily rename your classes, methods and variables with automatic correction of all places where they are used. To try it, place the caret at the symbol you want to rename, and press ⇧F6 (Refactor | Rename). Type the new name in the popup window that appears, or select one of the suggested names, and press Enter.

# 轻松重写基类的方法

You may easily override methods of the base class by pressing ⌃O (Code | Override Methods). To implement methods of the interfaces that the current class implements (or of the abstract base class), use ⌃I (Code | Implement methods).

# 查找适合上下文的方法和变量

The SmartType code completion greatly helps to find methods and variables that are suitable in the current context, by analyzing the expected type of the whole expression. So doing, Android Studio pinpoints the top five most suitable results and highlights them on the blue background. For example, type

and press ⌃⇧Space:

# 选择提示变量名并替换掉

When using Code Completion, you can accept the currently highlighted selection in the popup list with ⇥ key. Unlike accepting with the ⏎ key, the selected name will overwrite the rest of the name to the right of the caret. This can be especially useful for replacing one method or variable name with another.

# 关闭编辑器和工具窗口中选项卡

Did you know that you can close tabs in the editor and the tool windows of Android Studio without actually using the context menu commands? It is enough to point with your mouse cursor to a tab to be closed, and click the middle mouse button, or just use the Shift+click combination.

# 为类添加getter和setter方法

Using ⌘N (Code | Generate) in the editor, you can easily generate getter and setter methods for any fields of your class.

# 快速选择当前编辑元素(class,file,method or field)

To quickly select the currently edited element (class, file, method or field) in any view (Project view, Structure view or other), press ⌥F1.

The speed search is available in all the tree views: just start typing and you'll quickly locate the necessary item.

# 将焦点定位到编辑器

The ⎋ key in any tool window moves the focus to the editor. ⇧⎋ moves the focus to the editor and also hides the current (or last active) tool window. The F12 key moves the focus from the editor to the last focused tool window.

# 自动生成代码环绕

When you want to catch exceptions thrown by some code fragment, select it in the editor, press ⌥⌘T (Code | Surround With) and choose try / catch. The catch blocks for all the exceptions thrown inside the block will be generated automatically. You can customize the bodies of the generated catch blocks on the Code tab of File | Settings | File and Code Templates. Use other items in the list to surround with other constructs.

# new关键字提示 实现

The SmartType code completion may be used after the new keyword, to instantiate an object of the expected type. For example, type

and press ⌃⇧Space:

# 导航到抽象方法的实现处

To navigate to the implementation(s) of an abstract method, position the caret at its usage or its name in the declaration and press ⌥⌘B.

# 在编辑器通过单词选中扩展区域

⌥↑ (extend selection) in the editor selects the word at the caret and then selects expanding areas of the source code. For example, it may select a method name, then the expression that calls this method, then the whole statement, then the containing block, etc. You can also select the word at the caret and the expanding areas of the source code by double-clicking the target areas in the editor.

# 选中代码中的表达式

The Extract Variable refactoring helps you simplify complicated statements in your code. For example, in the code fragment below, you can select an expression in the code:

and press ⌥⌘V (Refactor | Extract | Variable...). This will result in the following:

# 注释的快捷键

You can comment or uncomment lines and blocks of code using ⌘/ and ⌥⌘/. ⌘/ comments or uncomments the current line or selected block with single line comments (//...). ⌥⌘/ encloses the selected block in a block comment (/.../). To uncomment a commented block press ⌥⌘/ anywhere inside it.

# 在编辑器中打开文档中的外部元素

To open your browser with documentation for the element at the editor's caret, press ⇧F1 (View | External Documentation). You must have the path to your browser set in the File | Settings | Web Browsers options and paths to documentation files added to your project (File | Project Structure...) to use this feature.

# 复制当前行

⌘D in the editor duplicates the selected block or the current line when no block is selected.

# 实时模板

Live Templates allow you to generate many typical code constructs in seconds! For example, type

in a method and press the Tab key to see what happens.

Use the Tab key to move between the template fields. See File | Settings | Live Templates for more details.

# 自动补全代码的(代码模板)

Live Templates allow you to generate many typical code constructs in seconds! For example, type

in a method and press the Tab key to see what happens.

Use the Tab key to move between the template fields. See File | Settings | Live Templates for more details.

# 查看有效参数清单

If the cursor is between the parentheses of a method call, pressing ⌘P brings up a list of valid parameters.

# 导航到最后一次编辑位置

⇧⌘⌫ (Navigate | Last Edit Location) brings you back to the last place where you made changes in the code. Pressing ⇧⌘⌫ a few times moves you deeper into your changes history.

# 查找 与 取消查找

Use ⇧⌘F7 (Edit | Find | Highlight Usages in File) to quickly highlight usages of some variable in the current file. Use ⌘G and ⇧⌘G keys to navigate through highlighted usages. Press ⎋ to remove highlighting.

# 格式化代码

Use Code | Reformat Code to reformat code according to your code style preferences (File | Settings | Code Style). You can also use Code | Optimize Imports to automatically optimize imports (remove unused imports, etc.). To access the corresponding settings, use File | Settings | Code Style | Imports.

# 查看历史记录恢复代码

To see your local history of changes in a file, invoke Local History | Show History from the context menu. You can navigate through different file versions, see the differences and roll back to any previous version. Use the same context menu item to see the history of changes on a directory. You will never lose any code with this feature!

# 查看方法的声明不滚动到该方法

Press ⌃⇧Q (View | Context Info) to see the declaration of the current method without the need to scroll to it.

# 查看最近打开过的文件 和 搜索

⌘E (View | Recent Files) brings a popup list of the recently visited files. Choose the desired file and press Enter to open it.

# 高亮错误显示部分跳转

Use F2/⇧F2 keys to jump between highlighted syntax errors. Use ⌥⌘↑/⌥⌘↓ shortcuts to jump between compiler error messages or search operation results. To skip warnings right click on the validation side bar / marker bar and choose Go to high priority problems only.

# 查看缩写

Use ⌘J to complete any valid Live Template abbreviation if you don't remember it. For example, type it and press ⌘J to see what happens.

# 显示方法之间的分隔线

To show separator lines between methods in the editor, open the editor settings and select the Show method separators check box in the Appearance page.

# 选中提示内容

When using basic code completion (⌃Space), type any characters that exist anywhere in an identifier. Press ⌃. to choose the selected (or first) suggestion.

# 快速在methods间移动

Use ⌃↑ and ⌃↓ keys to quickly move between methods in the editor.

# 去掉非必要空格

⌃⇧J shortcut joins two lines into one and removes unnecessary space to match your code style.

# 将最近的剪贴板内容插入

Use the ⇧⌘V shortcut to choose and insert recent clipboard contents into the text

# 创建自己的词典

If you lack words in the pre-defined dictionaries, you can create your own ones. A custom dictionary is a mere textual file with a .dic extension, with each word starting on a new line. All you have to do is to point to the directories where your dictionaries are stored, in the Spelling of the Settings dialog.

# 快速输入路径

You can jump directly to any deeply buried file, if you press ⇧⌘O, and type just a couple of characters of the enclosing directories and file names:

Use either a slash or a backslash as a delimiter.

To open any class or file in the editor at the desired line, press ⇧⌘O (Navigate | File), start typing the name, and choose the one from the suggestion list. Then type the colon (😃 and a line number. The selected file will open with the caret at the specified line.

# 查看类的继承层次结构

To see the inheritance hierarchy for a selected class, press ⌃H (Navigate | Type Hierarchy). You can also invoke the hierarchy view right from the editor to see the hierarchy for the currently edited class

# 调度过程中查看值

To easily evaluate the value of any expression while debugging the program, select its text in the editor (you may press a ⌥↑ a few times to efficiently perform this operation) and press ⌥F8.

# 调度过程中查看表达式的值

To quickly evaluate the value of any expression while debugging the program, hold Alt and click this expression to see its value and calculate it, call a method, etc.

# 快捷查看

The shortcuts such as F1 (View | Quick Documentation), ⌘P (View | Parameter Info), ⌘B (Navigate | Declaration) and others can be used not only in the editor but in the code completion popup list as well.

# 将类改为顶级类或移动到另一个类

When you invoke the Move refactoring (F6) on a nested class that is declared static, you are provided with an option to either make it a top-level class, or move it to another class.

# 提取变量

You can use the Extract Variable refactoring even on incomplete statements. Just press ⌥⌘V, and choose the desired expression:

# 快速打开文件

To open any particular method or field in the editor quickly, press ⌥⌘O (Navigate | Symbol) and start typing its name. Choose symbol from the drop-down list that appears.

# 查看最近更改

Use ⌥⇧C to quickly review your recent changes to the project.

# 快速切换各种方案

With a single keystroke, you can apply another code style/coloring scheme or keymap right from the editor. Just press ⌃` (View | Quick Switch Scheme), to specify the scheme you want to change.

# 完成当前语句

Use ⇧⌘⏎ to complete a current statement such as if, do-while, try-catch, return (or a method call) into a syntactically correct construct (e.g. add curly braces).

# 快速查看定义,无需开新选项卡

Use ⌥Space (View | Quick Definition), to quickly review definition or content of the symbol at caret, without the need to open it in a new editor tab.

# 将某字段、方法、类、文件 引入文档中某位置

第一步

The Edit | Copy Reference action can be used to insert a reference to a field/method/class/file into the current position in the editor. For example, go to the java.util.Collections JDK class, place the cursor within the EMPTY_MAP field and press ⌥⇧⌘C:

第二步

Then return to your source code and press ⌘V:

# 移动代码

The Code | Move Statement Up/Down action is useful for reorganizing the code lines in your file, e.g., for bringing a variable declaration closer to variable usage. Select a code fragment and press ⇧⌘↑ or ⇧⌘↓. The following pictures show an initial location of a code fragment, and the results of moving the selected fragment up and down.

When nothing is selected in the editor, the line at the cursor will be moved.

# 启动和调试代码快捷键

By pressing ⌃⌥R you can access the Run/Debug dropdown on the main toolbar, without the need to use your mouse.

# 显示导航栏

Navigation bar is a quick alternative to the Project view. Use ⌘↑ keyboard shortcut to show the navigation bar, and arrow keys to locate the necessary files or folders.

# 查找

You can bring forward the list of all usages of a class, method or variable across the whole project, and quickly jump to the selected usage. To do that, place the caret at the symbol's name or at its usage in code and press ⌥⌘F7 (Edit | Find | Show Usages in the main menu), scroll the list and click the desired usage.

# 检查

To quickly find and run an inspection, press ⌥⇧⌘I and start typing the name of the inspection or its group. Choose the desired inspection from the suggestion list and then specify the desired scope.

# 查看实现接口

You can view all methods of the implemented interfaces in a class, if you place the caret at the implements keyword in the class declaration, press ⇧⌘F7, and select the desired interface from the list:

# 比较两文件夹或文件

To compare two directories, select one or both of them in the Project view and press ⌘D.

To compare two jar files, select one or both of them in the Project view and press ⌘D.

# 查找 替换

It is very easy to toggle between find and replace functionality. When you perform search and replace in a file, pressing ⌘F shows the search pane. Pressing ⌘R adds field, where you can type the replace string. While in the Find in Path dialog, you can switch to replace by pressing ⇧⌘R. Same way, press ⇧⌘F to hide the Replace with field, and switch to mere search.

# 查看终端运行情况

Android Studio makes it possible to launch the embedded local terminal using keyboard only. Press ⌥F12, and see the terminal running.

# 查看文档

When in a Code Completion lookup, press F1 to show documentation for a lookup item, including class constructors. So doing, if a class has more than one constructor, the links are shown:

# 删除行

⌘⌫ in the editor deletes the whole line at the caret.

# 外面加一层嵌套

⎇enter

Alt + Enter(在mac中是option + Enter)是用于Flutter开发中经常要用到的的快捷键。可以单击任何一个widget,然后按Alt + Enter,就可以查看对该widget进行特定的操作。

# 删除未使用的import

如果我们正在开发一个项目,并导入了大量文件,但是到最后,有些文件其实是没有被使用到的,所以我们是不需要这些多余的导入的。直接使用Ctrl+Alt+O,就可以代替手动删除了所有未使用的import。

⌃⎇o