AndroidStudio已经用了两年左右了,对快捷键的使用一直如同段誉的六脉神剑一般,偶尔会biu
不出来,从来没有静下心来耐心的看完Tips
,为了避免这种尴尬,决定把Tips
完整的练习一遍并记录在案。
AndroidStudio版本:2.2
计算机操作系统: Windows 7
提示 ##
如果关闭了提示对话框,可在 Help | Tip of the Day 打开。
Welcome to Android Studio 2.2 You can quickly get familiar with the main features of the IDE by reading these tips.
You may try out the features described in the tips while this dialog stays open on the screen.
If you close the dialog, you can always get back to it from theHelp | Tip of the Day
main menu item.
Ctrl + N
在编辑器中 Ctrl + N
搜索类
。
也可以使用Ctrl+Shift+N
搜索项目中的任意文件
。
To open any class in the editor quickly, press
Ctrl+N (Navigate | 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
Ctrl+Shift+N (Navigate | File)
Ctrl+空格
代码补全提示,和搜狗输入法默认快捷键会冲突,修改即可
。
其实AndroidStudio在一次完整的输入会默认具有使用
Ctrl+空格
的效果。
除非是输入中断后才需要再次使用Ctrl+空格
做补全提示。
比如输入过程中鼠标焦点切换至tool window,再次切换回编辑器才需要手动Ctrl+空格
唤起补全提示。)
The Code Completion feature lets you quickly complete different kinds of tatements in the code.
For example, start typing a class name and pressCtrl+空格
to complete it. When multiple choices are available, they are shown in the lookup list.
提供建议的变量名称
The CodeCompletion feature can suggest a name for a variable when you declare it. For example, start typing
private FileOutputStream
and pressCtrl+空格
.You can customize name prefixes for local variables, parameters, instance and static fields in
File | Settings | Code Style
.
提示已存在(自定义)的方法
When using basic code completion (
Ctrl+空格
), type any characters that exist anywhere in an identifier.
提供多种类型文件的提示,如图所示的HTML
文件。
Use Basic Completion (
Ctrl+空格
) for completing words in text and comments in files of many different types.
All the words from the current file that start with the typed prefix will appear in the lookup list.
在HTML
、CSS
等文件中提供图片名称(Local图片)提示。
Use Basic Completion (
Ctrl+空格
) within HTML, CSS and other files, for
completing image file names.
甚至包含HTML
、CSS
、JavaScript
文件中的属性、参数、标签、选择器等。
You can use Basic Completion (
Ctrl+空格
) in HTML, CSS and JavaScript files, for completing attributes, parameters, tags, selectors, etc.
You can use Basic Completion (
Ctrl+空格
) within Java String literals and in other file types, for completing.properties
keys.
输入多个小写字母,智能对应被提示方法的驼峰每个单词首字母
When using basic code completion (
Ctrl+空格
), you don't need to type upper-case letters in CamelHump names. It is enough to type the initial letters of the camel names in lower case, and they will be smartly recognized.
Show Usages
快速查找被使用位置
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
Alt+F7 (Edit | Find | Find Usages
in the popup menu).
相比Alt+F7
,该方法在编辑器上弹出一个选择列表框,而不用在工具窗口显示被使用类的层级结构,更清晰明了。
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
Ctrl+Alt+F7
(Edit | Find | Show Usages
in the main menu), scroll the list and click the desired usage.
Ctrl+Q
快速查看文档(插入符所定位的类或方法)
To quickly see the documentation for a class or method at caret, press
Ctrl+Q (View | Quick Documentation)
.
Ctrl+B
跳转至声明位置。
插入符放在类、方法、变量使用处,点击Ctrl+B
即跳转至声明位置,等同于按下Ctrl
时鼠标单击效果。(经测试:在声明处使用也可跳转至使用处)
To navigate to the declaration of a class, method or variable used somewhere in the code, position the caret at the usage and press
Ctrl+B (Navigate | Declaration)
. You can also click the mouse on usages with theCtrl
key pressed to jump to declarations.
Ctrl+F12
显示大纲/文件结构
You can quickly navigate in the currently edited file with
Ctrl+F12 (Navigate | File Structure)
. It shows the list of members of the
current class. Select an element you want to navigate to and press theEnter
key or theF4
key. To easily locate an item in the list, just start typing its name.
Shift+F6
重命名 类、方法、变量名称,并自动修改所有引用。
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 pressShift+F6 (Refactor | Rename)
. Type the new name in the popup window that appears, or select one of the suggested names, and pressEnter
.
Ctrl+O
Ctrl+O
重写父类方法,Ctrl+I
实现接口方法
You may easily override methods of the base class by pressing
Ctrl+O (Code | Override Methods)
.
To implement methods of the interfaces that the current class implements (or of the abstract base class), useCtrl+I (Code | Implement methods)
.
Ctrl+Shift+空格
自动补全代码
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 green background. For example, type
and press
Ctrl+Shift+空格
:The SmartType completion also works after the return keyword, in an assignment, in an argument list of a method call and other places.
The SmartType code completion may be used after the
new
keyword, to instantiate an object of the expected type. For example, typeand press
Ctrl+Shift+空格
:
When you need to cast an expression value to the required type the SmartType code completion will help you. For example, type
String s = (<caret is here>
and pressCtrl+Shift+空格
to see what happens.
Tab&Enter
When using Code Completion, you can accept the currently highlighted selection in the popup list with
Tab
key.
Unlike accepting with theEnter
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.
Shift+click
关闭选项卡,Alt + Click
关闭其他选项卡
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.
Alt+Insert
生成构造函数、Getter and Setter、toString()等方法。
Using
Alt+Insert (Code | Generate)
in the editor, you can easily generate getter and setter methods for any fields of your class.
Alt+F1
如图所示,可以快速切换到不同的视图:项目视图(Project, Packages, Android)、文件结构、在Exporler中显示等等。
To quickly select the currently edited element (class, file, method or field) in any view (
Project
view,Structure
view or other), pressAlt+F1
.
speed search in the tree views
在树视图中快速查找:鼠标选中树输入名称即可。
The speed search is available in all the tree views: just start typing and you'll quickly locate the necessary item.
Focus of the Editor
焦点移动:
Esc
焦点从工具窗口移动至编辑器Shift+Esc
关闭当前(最后一个)工具窗口并将焦点移动至编辑器F12
焦点从编辑器移动至最后聚焦工具窗口
The
Esc
key in any tool window moves the focus to the editor.Shift+Esc
moves the focus to the editor and also hides the current (or last active) tool window.
TheF12
key moves the focus from the editor to the last focused tool window.
Ctrl+Alt+T
生成try / catch
、if
、for
等代码模板
When you want to catch exceptions thrown by some code fragment, select it in the editor, press
Ctrl+Alt+T
(Code | Surround With
) and choosetry / 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 theCode
tab ofFile | Settings | File and Code Templates
.
Use other items in the list to surround with other constructs.
Ctrl+Alt+B
导航至抽象方法的实现,多个实现会弹出列表。
To navigate to the implementation(s) of an abstract method, position the caret at its usage or its name in the declaration and press
Ctrl+Alt+B
.
Ctrl+W
选择范围,多次点击后逐渐扩大,如:选择方法中某个方法引用,多次点击Ctrl+W
,方法表达式 > 该行 > 包含块 > 整个方法 > 整个类块
Ctrl+W
(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.
Ctrl+Alt+V
将方法参数中复杂表达式提取成一个变量并将引用做个参数使用。
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
Ctrl+Alt+V
(Refactor | Extract | Variable...
). This will result in the following:
选择一个表达式后使用Ctrl+Alt+V
会生成一个变量并被引用,而且可以选择变量名。
如图:选择第一行的绿色区域表达式,则会生成第五行的变量并被第六行引用。
You can use the Extract Variable refactoring even on incomplete statements. Just press
Ctrl+Alt+V
, and choose the desired expression:
comment or uncomment
生成注释与取消注释
You can comment or uncomment lines and blocks of code using
Ctrl+斜杠
andCtrl+Shift+斜杠
.Ctrl+斜杠
comments or uncomments the current line or selected block with single line comments (//...
).Ctrl+Shift+斜杠
encloses the selected block in a block comment (/*...*/
).
To uncomment a commented block pressCtrl+Shift+斜杠
anywhere inside it.
Shift+F1
在浏览器中打开文档。
To open your browser with documentation for the element at the editor's caret, press
Shift+F1
(View | External Documentation
).
You must have the path to your browser set in theFile | Settings | Web Browsers
options and paths to documentation files added to your project (File | Project Structure...
) to use this feature.
Ctrl+D
在编辑器复制所选块,如果未选则复制当前行。
Ctrl+D
in the editor duplicates the selected block or the current line when no block is selected.
Try Live Templates
使用Live Templates, 常用的比如 Toast,可以在设置中自定义常用模板。
文中所说的Tab切换字段测试未生效
。
Try Live Templates
Live Templates allow you to generate many typical code constructs in seconds! For example, typein a method and press the Tab key to see what happens.
Use the
Tab
key to move between the template fields. SeeFile | Settings | Live Templates
for more details.
Ctrl+P
光标在方法的括号之间,点击Ctrl+P
可以调出参数列表
If the cursor is between the parentheses of a method call, pressing
Ctrl+P
brings up a list of valid parameters.
Ctrl+Shift+Backspace
单次Ctrl+Shift+Backspace
可以返回至最后一次修改位置,多次调用则返回更久的历史修改位置
Ctrl+Shift+Backspace
(Navigate | Last Edit Location
) brings you back to the last place where you made changes in the code.
PressingCtrl+Shift+Backspace
a few times moves you deeper into your changes history.
Ctrl+Shift+F7
类似Find
查询方法
按Ctrl+Shift+F7
高亮显示所选变量,F3
和Shift+F3
分别向上和向下跳转,
按Esc
退出高亮模式。
Use
Ctrl+Shift+F7
(Edit | Find | Highlight Usages in File
) to quickly highlight usages of some variable in the current file.
UseF3
andShift+F3
keys to navigate through highlighted usages.
PressEsc
to remove highlighting.
view all methods of the implemented interfaces in a class
光标在implemented
处按Ctrl+Shift+F7
查看类中所有的接口实现方法。
经测试不会如图弹出框,而是将实现方法在编辑器中高亮显示并在IntelliJ IDEA
底部栏显示数量等提示。
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
Ctrl+Shift+F7
, and select the desired interface from the list:
view all statements within the method where certain exceptions can be caught
查看方法中所有可以捕获异常的语句:将光标放在方法声明中的throws关键字处,按Ctrl + Shift + F7
并从列表中选择所需的异常类,该功能对try catch
同样适用。
You can view all statements within the method where certain exceptions can be caught. Just place the caret at the
throws
keyword in a method declaration, pressCtrl+Shift+F7
and select the desired exception class from the list. This will also work fortry
andcatch
.
Reformat Code / Optimize Imports
格式化代码/优化引用
Use
Code | Reformat Code
to reformat code according to your code style preferences (File | Settings | Code Style
).
You can also useCode | Optimize Imports
to automatically optimize imports (remove unused imports, etc.). To access the corresponding settings, useFile | Settings | Code Style | Imports
.
Local History | Show History
文件右键选择Local History | Show History
可以查看本地历史,并且可浏览不同的版本文件,查看差异并回滚到任何以前的版本。
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!
Alt+Q
不用滚动即可查看当前方法声明所在类
Press
Alt+Q
(View | Context Info
) to see the declaration of the current method without the need to scroll to it.
Ctrl+E
Ctrl+E
在编辑器中使用,会弹出最近访问文件列表
在工具窗口使用,会弹出最近 查询使用(Find Usages
)列表
Ctrl+E
(View | Recent Files
) brings a popup list of the recently visited files. Choose the desired file and pressEnter
to open it.Besides recent files, you can bring up results of the usage searches you have performed recently. To do that, use the same
Ctrl+E
shortcut with the Find tool window having the focus, and select the desired find usages result from theRecent Find Usages
popup.
Go to high priority problems only
使用F2
/Shift+F2
可以在高亮错误间上下跳转。
使用Ctrl+Alt+向上箭头
/Ctrl+Alt+向下箭头
可以在编译错误间上下跳转,search operation results
是什么不了解。
Use
F2
/Shift+F2
keys to jump between highlighted syntax errors.
UseCtrl+Alt+向上箭头
/Ctrl+Alt+向下箭头
shortcuts to jump between compiler error messages or search operation results.
To skip warnings right click on the validation side bar / marker bar and chooseGo to high priority problems only
.
Ctrl+J / valid Live Template abbreviation
Ctrl+J
调出Live Template
可用列表
Use
Ctrl+J
to complete any valid Live Template abbreviation if you don't remember it. For example, type it and press Ctrl+J to see what happens.
Show method separators
设置显示方法线,视觉上更容易分隔方法
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.
move between methods in the editor
用Alt+向上箭头
和 Alt+向下箭头
在方法间快速上下跳转
Use
Alt+向上箭头
andAlt+向下箭头
keys to quickly move between methods in the editor.
Ctrl+Shift+J / joins two lines into one
Ctrl+Shift+J
可将多行合并成一行代码
Ctrl+Shift+J
shortcut joins two lines into one and removes unnecessary space to match your code style.
Refactor | Copy
复制当前类
Use
Refactor | Copy
to create a class which is a copy of the selected class. This can be useful, for example, when you need to create a class which has much in common with some existing class and it's not feasible to put the shared functionality in a common superclass.
Ctrl+Shift+V
Ctrl+Shift+V
显示 最近粘贴板内容列表
,可供选择
Use the
Ctrl+Shift+V
shortcut to choose and insert recent clipboard contents into the text.
Ctrl+H
查看类的继承层次结构
To see the inheritance hierarchy for a selected class, press
Ctrl+H
(Navigate | Type Hierarchy
). You can also invoke the hierarchy view right from the editor to see the hierarchy for the currently edited class.
breakpoint marker
设置好断点后,在断点上右键
显示的快捷菜单中,可以快速启用
/禁用
、调整其属性(设置触发条件
、单次触发后移除
等)
Right-clicking on a breakpoint marker (on the bar to the left from the text) invokes the speedmenu where you can quickly enable/disable the breakpoint or adjust its properties.
evaluate the value of any expression
调试中可以通过Alt+F8
计算所选表达式值
To easily evaluate the value of any expression while debugging the program, select its text in the editor (you may press a
Ctrl+W
a few times to efficiently perform this operation) and pressAlt+F8
.
也可以通过 按住Alt
键然后点击表达式计算值
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.
Ctrl+Q
Ctrl+Q
快速查看文档Ctrl+P
查看参数信息Ctrl+B
跳转至声明处
The shortcuts such as
Ctrl+Q
(View | Quick Documentation
),Ctrl+P
(View | Parameter Info
),Ctrl+B
(Navigate | Declaration
) and others can be used not only in the editor but in the code completion popup list as well.
accept the currently highlighted selection in the popup list
自己kuo mo
When using Code Completion, you can accept the currently highlighted selection in the popup list with the period character (
.
), comma (,
), semicolon (;
), space and other characters.
The selected name is automatically entered in the editor followed by the entered character.
short description of main menu
为了帮助了解主菜单的每一项功能,鼠标放在按钮上后显示该功能描述
。
To help you learn the purpose of each item in the main menu, its short description is shown in the status bar at the bottom of the application frame when you position the mouse pointer over this item.
pattern search
模糊查询
For the pattern search in the
Go to Class
,Go to Symbol
andGo to File
pop-up frames, use*
and space symbols.*
stands for any symbol.
Space at the end means the end of a pattern, and the preceding string will be considered not just a prefix but a whole pattern. The list of the suggested names will be reduced accordingly.
Move refactoring on an inner class that is declared static
静态内部类重构:在静态内部类中点击F6
弹出提示框,可选择升级成顶级类
(即新建一个类文件)或移动至其他类中
(仍然是静态内部类)
When you invoke the Move refactoring (
F6
) on an inner class that is declaredstatic
, you are provided with an option to either make it a top-level class, or move it to another class.
Ctrl+Alt+Shift+N
查询方法
To open any particular method or field in the editor quickly, press
Ctrl+Alt+Shift+N
(Navigate | Symbol
) and start typing its name. Choose symbol from the drop-down list that appears.
Alt+Shift+C
快速查看最近对项目所做的更改
Use
Alt+Shift+C
to quickly review your recent changes to the project.
Ant property or target
使用Ant
属性,不存在可以在当前界面快速创建
You can start referring to an Ant property or target even if it is not defined yet. An intention action feature will suggest you to automatically create the necessary tag, without the need for you to leave your current editing location.
Quick Switch Scheme
快速切换主题
:切换颜色方案
、切换代码样式方案
、切换快捷键方案
、切换外观
With a single keystroke, you can apply another code style/coloring scheme or keymap right from the editor. Just press
Ctrl+后引号
(View | Quick Switch Scheme
), to specify the scheme you want to change.
Ctrl+Shift+Enter
使用Ctrl + Shift + Enter
完成当前语句,如if
,do-while
,try-catch
,return
(或方法调用)到语法正确的结构中(例如添加花括号
)
Use
Ctrl+Shift+Enter
to complete a current statement such asif
,do-while
,try-catch
,return
(or a method call) into a syntactically correct construct (e.g. add curly braces).
camel words
When in the
Go to Class
,Go to Symbol
, orGo to File
popup, you can ease the search by filtering the lookup list with the help of the "camel words" prefixes.
Quick Definition
查看方法定义:在接口和父类中点击Ctrl+Shift+I
可查看子类和实现类,如果有多个定义可通过Back(向左箭头
)和Forward(向右箭头
)切换,Show Source(Ctrl+Enter
)查看,Edit Source(F4
)修改
Use
Ctrl+Shift+I
(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.
Copy Reference
使用Ctrl+Alt+Shift+C
复制完整引用。
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 thejava.util.Collections
JDK class, place the cursor within theEMPTY-MAP
field and pressCtrl+Alt+Shift+C
:Then return to your source code and press
Ctrl+V
:You can also copy references in the
GotoClass/GotoSymbol/GotoFile
dialogs. Just pressCtrl+C
on any element in the lookup list.
Move Statement Up/Down
Ctrl+Shift+向上箭头
和 Ctrl+Shift+向下箭头
可以向上
和向下
移动代码
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 pressCtrl+Shift+向上箭头
orCtrl+Shift+向下箭头
.
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.
Run/Debug dropdown
按Alt+Shift+F10
可以访问Run
/Debug
下拉菜单
By pressing
Alt+Shift+F10
you can access the Run/Debug dropdown on the main toolbar, without the need to use your mouse.
Quick Definition Viewer
自己kuo mo
The
Quick Definition Viewer
(Ctrl+Shift+I
) can also be used for items in lookup lists that appear on code completion and class/file/symbol navigaton commands.
Show Applied Styles For Tag
选中HTML标签
右键选择Show Applied Styles For Tag
在 Tool Window
即显示应用的样式列表
You can quickly review all styles currently applied to an HTML tag, by right-clicking the tag name and selecting
Show Applied Styles For Tag
from the context menu:
view the image referenced at caret
自己kuo mo
You can quickly view the image referenced at caret by using the Quick Definition (
Ctrl+Shift+I
). The underlying image will be opened in a popup instead of a separate editor tab.
Refactor | Rename
可以直接从HTML重命名CSS选择器
It is possible to rename CSS selectors directly from HTML. Position the caret at the selector to be renamed and press
Shift+F6
(Refactor | Rename
).
shortcut to show the navigation bar
使用Alt + Home
显示导航栏,使用箭头键来定位到文件或文件夹。
Navigation bar is a quick alternative to the
Project
view.
UseAlt+Home
keyboard shortcut to show the navigation bar, and arrow keys to locate the necessary files or folders.
shortcut to show or hide this tool window
Changes
工具窗口在单个视图中显示所有已删除,已修改和未版本化的文件。
并可以执行所有必要的版本控制操作:提交更改
,管理更改列表
,添加资源至版本控制
,检查差异
等。
使用Alt + 9
显示或隐藏此工具窗口。
The
Changes
tool window shows all deleted, modified, and unversioned files in a single view. UseAlt+9
keyboard shortcut to show or hide this tool window.
From theChanges
tool window you can perform all the necessary version control actions:commit changes
,manage changelists
,put resources under version control
,examine differences
and more.
antivirus protection
防病毒保护
If you notice that Android Studio works slowly, consider the possibility to reduce the number of folders under antivirus protection.
Each antivirus check in your project consumes resources. You can significantly improve the performance, if you exclude certain folders from the antivirus protection.
quickly open a Maven project
选择pom.xml
文件即可打开Maven
项目
You can quickly open a Maven project by selecting a
pom.xml
file in theFile | Open
dialog. The corresponding Maven project is imported with default settings, without launching the wizard.
Shelve Changes
搁置更改
If you don't want to commit some of your changes to the repository, you can set them aside for a while, by moving to a separate changelist, or by putting them to a shelf. Select such file in the
Local
tab of theChanges
tool window, and on the context menu chooseMove to Another Changelist
, orShelve Changes
.
quickly open an Eclipse project
快速打开一个Eclipse
项目:选择.classpath
或者.project
文件,相应的Eclipse 项目即会以默认设置被导入。
You can quickly open an Eclipse project by selecting a
.classpath
or.project
file in theFile | Open
dialog. The corresponding Eclipse project is imported with default settings, without launching the wizard.
quickly find a menu command or toolbar action
快速找到菜单命令或工具栏操作:只需按Ctrl + Shift + A
(主菜单上的Help | Find Action
”),然后开始输入操作名称,而不需要查看菜单。
To quickly find a menu command or toolbar action, you do not need to look through the menus. Just press
Ctrl+Shift+A
(Help | Find Action
on the main menu) and start typing the name of the action. Choose the desired action from the suggestion list.
quickly find and run an inspection
inspection
和 lint 是AndroidStudio
提供的代码静态分析工具
,可以检查项目中存在的问题(xml文件中是否存在hardcode
、未用到的资源
、可能存在的bug
等等),改善项目以帮助开发出规范的App。
inspection
检查项可以在Settings | Editor | Inspection
查看,也可以配置单项的严重程度和作用域。
快速查找并运行检查:按Ctrl+Alt+Shift+I
后输入需要查询项名或组名,然后在列表中选择后开始检查
To quickly find and run an inspection, press
Ctrl+Alt+Shift+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.
quickly find a setting
快速查询设置:Ctrl + Alt + S
打开设置,可在搜索框输入搜索。
You can quickly find a setting you need in the
Settings/Preferences
dialog, without browsing through the numerous options. Just type some characters that, in your opinion, exist in the option description, and the list of settings will reduce to the matching ones. Select the desired entry, and see the setting that contains the entered characters highlighted:
searching for a text string in a file
在文件中搜索文本字符串时,可用向下箭头
显示最近输入的列表
When searching for a text string in a file, use recent history: with the search pane already open, click the down arrow to show the list of recent entries.
finding text in the current file
在当前文件中查找文本(Ctrl + F
)时,不需要输入整个搜索字符串:可以使用代码提示功能
,输入部分字母按Ctrl +空格
,从弹出的建议列表中选择所需字符串。
When you are finding text in the current file (
Ctrl+F
), you don't need to type the whole search string: Basic Code Completion is available in the search field. Start typing, pressCtrl+空格
, and select the desired string from the suggestion list.
To view all exit points of a method
查看方法所有出口点,如 return语句
,break语句
。
光标放在某一出口点,按Ctrl+Shift+F7
即会高亮显示。
To view all exit points of a method, place the caret at one of them, e.g. the return statement, and press
Ctrl+Shift+F7
:
invoke a quick fix or intention action
Alt+Enter
快速修复
When you press
Alt+Enter
to invoke a quick fix or intention action, press the right arrow key to reveal the list of additional options. Depending on the context, you can choose to disable inspection, fix all problems, change inspection profile, etc.
navigate to any part of the file path
导航到文件的任何层级(父)目录:Ctrl+Click
(Windows) or Cmd+Click
(MacOS)点击后,弹出从盘符到文件所在目录间的所有目录,选择所需目录后会在资源管理器中打开(MacOS系统在外部浏览器中打开)。
Ctrl+Click
(on Windows) orCmd+Click
(on MacOS) a tab in the editor to navigate to any part of the file path. Select the necessary element in the drop-down, and the corresponding file path opens in an external browser (e.g., in the Explorer, if your OS is Windows).
Issue Navigation
Android Studio
可以从注释添加页面跳转至问题跟踪器,问题跟踪器可以在Settings | Version Control | Issue Navigation
中定义。
提交更改列表并输入注释时,保证问题导航模式可以匹配。稍后浏览Repository
中的更改列表时,此类注释将变为超链接。
单击超链接可跳转至任务跟踪器中的问题。
Android Studio lets you jump from your check-in comment to an issue in your task tracker.
All you have to do is to define issue navigation patterns in theSettings | Version Control | Issue Navigation
dialog:When you commit a changelist, and type the check-in comment, make sure it matches one of your issue navigation patterns. Later, when you browse through the changelists in the repository, such comments turn into hyperlinks:
Clicking a hyperlink brings you directly to an issue in your task tracker
choose the desired color from the color picker
从颜色选择器中取色:Android Studio
简化了CSS
文件中取色,颜色属性在编辑器的左侧沟槽有相应颜色的图标,点击颜色图标可以打开颜色选择器取色
。
Android Studio simplifies your work with colors in CSS files. The
color
properties have the icons of the corresponding color in the left gutter area of the editor.
Click color icons to choose the desired color from the color picker.
Create Test
Android Studio
帮助直接从类声明创建测试用例
。光标定位在编辑器中的类名称处,按Alt + Enter
,然后从建议列表中选择创建测试
。
Android Studio helps create test cases directly from class declaration. With the caret at the class name in the editor, press
Alt+Enter
, and chooseCreate Test
from the suggestion list:
easily make column selection
同时选择多行
,如 Sublime Text
按Alt键的同时拖动鼠标
即可进行列选择。
You can easily make column selection by dragging your mouse pointer while keeping the
Alt
key pressed.
File Colors
文件颜色可以在Appearance & Behavior | File Colors
设置(自定义颜色),也可以添加Scope
(域)。
You don't need to guess which
index.html
file you are looking at...
Make the editor tabs and lines in navigation lists stand out using theFile Colors
page of the project settings.
whole line at caret is copied
如果在编辑器中不选中任何内容,按 Ctrl + C
会复制光标所在的整行内容
If nothing is selected in the editor, and you press Ctrl+C, then the whole line at caret is copied to the clipboard.
Move to Another Changelist
你可以将任何文件移动至选择的更改列表中:在Local Changes
中选中文件右键Move to Another Changelist
选择即可。
You can move any file to a changelist of your choice. To do that, just choose
Move to Another Changelist
on the file context menu in the Changes tool window:
pre-defined dictionaries
在内置的拼写检查器
的帮助下,保持源代码不会出现错别字。
预定义的字典将会检查所有文本,包括注释
,字符串
和文字
,所有错别字都会突出显示
,这样就可以选择正确的单词,接受当前拼写或禁用检查。
用Alt + Enter
查看可用操作的列表。
Keep your source code typo-free with the help of the built-in Spellchecker.
All texts, including comments, textual strings and literals, are inspected against the pre-defined dictionaries. All typos are highlighted, which leaves you with the task of choosing the correct word, accepting the current spelling, or disabling inspection.
Use
Alt+Enter
to see the list of available actions.
custom dictionary
如果在预定义的词典中缺少词语,可以创建自己的词典。自定义词典只是一个具有.dic
扩展名的文本文件,每个单词从一个新行开始。
在Editor | Spelling
中通过Dictionaries
添加.dic
文件存储目录即可,也可通过Accepted Words
添加单词。
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 theSpelling
of theSettings
dialog.
VCS Operations
所有必需的VCS命令只需点击一下即可。
按Alt+后引号
,或在主菜单选择VCS | VCS Operations Popup
即弹出VCS命令选择列表。
All your most indispensable VCS commands are just one-click away...
ChooseVCS | VCS Operations Popup
on the main menu, and get a popup with the VCS commands that are relevant to the current context:
Use the Switcher
使用切换器(Ctrl + Tab
)在打开的文件和工具窗口之间切换。
按住Ctrl
键,使用向上
和向下
箭头键,Tab
或Shift + Tab
;Alt
进行导航;使用Delete
或BackSpace
关闭编辑器选项卡或隐藏工具窗口。
经测试:弹出切换器后,用Ctrl+方向键
更方便。
Use the Switcher (
Ctrl+Tab
) to switch between open files and tool windows. KeepingCtrl
pressed, use theUp
andDown
arrow keys,Tab
orShift+Tab
,Alt
for navigation; useDelete
orBackSpace
to close editor tab or hide a tool window.
open an external file for editing
将文件从Explorer
或 Finder
拖入编辑器就可以打开外部文件。
You can easily open an external file for editing, if you just drag it from the Explorer or Finder to the editor.
closing all tabs in the editor
有两种方法关闭编辑器中的其他(所有)选项卡。
在选项卡上右键,选择
Close Others
按住
Alt
键,单击编辑器选项卡关闭按钮
There are two ways of closing all tabs in the editor, except the current one:
First, right-click the editor tab, and choose Close Others on the context menu.
Second, keeping the Alt key pressed, click on the editor tab.
jump directly to any deeply buried file
可以直接跳转到深层级文件,如果你按Ctrl + Shift + N
,并只输入几个字符的封闭目录和文件名。
例如 MyProject/toplevelDir/level1Dir/level2Dir/level3Dir/deeplyBuriedFile.html
:
只需要输入
t/l/l/d
即可查询到deeplyBuriedFile.html
文件。输入l/l/可查询到
level2Dir
和level3Dir
。
You can jump directly to any deeply buried file, if you press Ctrl+Shift+N, and type just a couple of characters of the enclosing directories and file names:
Use either a slash or a backslash as a delimiter.
open any class or file in the editor
打开项目中的任意文件
并定位到指定行
: [文件匹配内容
]:
[行数
],如下图
To open any class or file in the editor at the desired line, press
Ctrl+Shift+N
(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.
Show Diff of Version control
显示版本控制的差异
Version control annotations show the latest changes of each line in one click.
Just right-click an annotation and use theShow Diff
command in the context menu.
compare two directories
比较两个目录:在项目视图
中选择目录,按Ctrl+D
即弹出比较窗口。
To compare two directories, select one or both of them in the
Project
view and pressCtrl+D
.
hide/show the tool windows bars
点击左下角图标
可以隐藏工具窗口,双击Alt
,工具窗口暂时显示。
If you need more workspace, you can hide the tool windows bars: click in the lower left corner.
If necessary, you can show the tool window buttons just for a moment. To do that, press the keyAlt
(for Windows/*nix) orCommand
(for Mac) twice and keep it down. While the key is pressed, the tool window buttons are visible.
exclude any file from your project
纯文本会被索引
、检查
、代码完成
功能忽略:文件右键后选择标记为纯文本
,标记成功也可以右键取消标记。测试时未发现该功能
。
You can exclude any file from your project. As a result, such a file will be ignored by indexing, inspection and code completion.
In theProject
tool window, select the file you want to ignore, and chooseMark as plain text
in its context menu.
If necessary, you can always return the file to its original type using theMark as <file type>
context menu command.
Commit Changes
Ctrl + K
快速调用 “提交更改”
对话框。对话框显示项目中的所有修改,提供文件状态的概要信息,并在提交之前提出改进建议。改进意见
:通过代码分析,提示Review
, 选择Review后在工具栏显示建议列表。
The keyboard shortcut
Ctrl+K
enables you to quickly invoke theCommit Changes
dialog.
This dialog shows all modifications in project, gives summary information of file status and suggests improvements before check-in.
toggle between find and replace
在搜索
和替换
间切换:按下Ctrl+F
后显示搜索面板,按Ctrl+R
后添加内容,可以替换搜索内容。按下Ctrl+Shift+R
弹出替换弹出框,可以更多选项如:预览
、作用域
、过滤条件
。
It is very easy to toggle between find and replace functionality.
When you perform search and replace in a file, pressingCtrl+F
shows the search pane. PressingCtrl+R
adds field, where you can type the replace string.
While in theFind in Path
dialog, you can switch to replace by pressingCtrl+Shift+R
. Same way, pressCtrl+Shift+F
to hide theReplace with
field, and switch to mere search.
Scope-Based
如果你一个大型项目,使用多个TODO
项目,请按范围进行过滤。
使用TODO工具窗口
中的“基于范围”
选项卡仅显示与感兴趣范围相关的项。
If you are working on a large project, with numerous TODO items, filter them by scopes.
Use the Scope-Based tab in the TODO tool window to show only those items that pertain to the scope of interest.
TODO tool window
代办工具窗口
可以通过Preview Source
预览每项代办事项。
TODO
tool window lets you preview each of the encountered TODO items - just click the preview button on the toolbar.
method signature quick fix
方法签名快速修复
:如果方法签名已更改(包括参数、返回值等),Android Studio会突出显示与文档注释不同步的代码,并建议快速修复。
If a method signature has been changed, Android Studio highlights the tags that ran out of sync with the documentation comment and suggests a quick fix:
Remove the tasks
使用冗长的任务列表时,不需要逐个删除它们。选择几个任务,使用Shift
或Control
/ Command
键,单击向右箭头,然后单击删除。
When working with a lengthy list of tasks, you don't need to delete them one by one. Select several tasks, using
Shift
orControl/Command
keys, click the right arrow, and then clickRemove
.
run/debug group
如果有太多的相同类型的运行/调试配置,可以将它们分组到文件夹。
If there are too many run/debug configurations of the same type, you can group them into folders, and thus distinguish them visually.
Live Templates
在Settings | Live Templates
页面中可以快速搜索模板。
In the
Live Templates
settings, use speed search to find templates with certain text in the template abbreviation, body or description.
Start typing the desired text, and the list of available templates will shrink to show matching templates only:
Edit RegExp
You can avoid escaping backslashes in your regular expressions. Start typing a regular expression, then press
Alt+Enter
and chooseEdit RegExp
. The regular expression opens in a separate tab in the editor, where you can type backslashes as is.
All changes are synchronized with the original regular expression, and escapes are presented automatically. When ready, just pressEsc
to close the regular expression editor.
Editor | Emmet
Speed up HTML, XML or CSS development with
Emmet
.
Enable this framework in the corresponding page of theEditor | Emmet
node (Settings/Preferences
):
*.properties
All escaped characters in the
*.properties
files in the format\uXXXX
, are displayed in the resource bundle editor as un-escaped unicode literals.
Vice versa, if a non-ASCII character is entered in the resource bundle editor, it is reflected in the underlying*.properties
file as a corresponding escaped character in the format\uXXXX
.
For example, if the*.properties
file contains a property value
then the resource bundle editor will show
line separators
To view which line separators style is used in the current file, look at the Status Bar:
To change the current line ending style, just click the spinner.
line separators
You do not need to open a file in the editor to change its line separator style. Use the
Project tool window
instead: select one or more files, or folders, point toFile | Line Separators
on the main menu, and then choose the desired line ending style.
For a directory, new line separator applies recursively.
list of refactorings
If you place the caret at certain symbol and press
Ctrl+Alt+Shift+T
, you will see the list of refactorings applicable to the current context.
Favorites
You want your bookmarks and breakpoints to be always at hand, so that you can easily navigate through them?
They are visible in theFavorites
tool window, which you can dock or float as required:
drop file onto the Favorites tool window
You can drag an external file from the Explorer or Finder, and drop it onto the Favorites tool window.
Tune the Android Studio tool windows layout
Tune the Android Studio tool windows layout to make better use of your screen.
Toggle between the vertical and side-by-side placement of the tool windows by Ctrl+Click/Cmd+Click on the splitter:
Terminal
You don't need to leave Android Studio to work with your favorite shell. Just click the Terminal tool window button, and enjoy using the embedded local terminal.
define your favorite shell
For the embedded local terminal, you can define your favorite shell, default tab name, and other settings. Choose
File | Settings
on the main menu, and then open the pageTerminal
.
Enable the horizontal scrolling
Enable the horizontal scrolling with the mouse wheel by holding the Shift key.
double pressing the Shift key
Android Studio allows you to search through the classes, files, tool windows, actions, settings, and symbols of your project by double pressing the
Shift
key.
autopopup Code
When using autopopup Code Completion, you can select the first item using
Ctrl+句
点. The selected name is automatically entered in the editor followed by dot.
close autopopup
When an autopopup completion is active,
Ctrl+向下箭头
andCtrl+向上箭头
will close it and move the caret down or up in the editor.
"camel words" ease the search
When in the Code Completion lookup, you can ease the search by filtering the list with the help of the "camel words" prefixes.
suggest to get an element from this array
Pressing the same shortcut after you have invoked Smart-type Completion when there's an array of expected type in context will suggest to get an element from this array.
suggest to convert searched for arrays using Arrays.asList() call
Pressing the same shortcut after you have invoked Smart-type Completion when a collection type is expected will search for arrays with same component type and suggest to convert them using Arrays.asList() call.
search for chained expressions
Pressing the same shortcut after you have invoked Smart-type Completion will search for chained expressions which have expected type.
accept the currently highlighted selection in the popup list
When using Code Completion, you can accept the currently highlighted selection in the popup list with the
Ctrl+Shift+Enter
, Android Studio will not just insert the selected string, but also will do its best to turn current code construct into syntactically correct one (balance parentheses, add missing braces and semicolons, etc.)
accept the currently highlighted selection in the popup list In Java
When using Code Completion in Java, you can accept the currently highlighted selection in the popup list with the exclamation sign (!) character. It will be inserted before the boolean method or variable you were completing, thus negating the whole expression.
After pressing '!':
method to be imported statically
To quickly complete a method call of a static method located anywhere in your project, libraries or JDK, enter a prefix and press Ctrl+空格 twice. You'll see all the matching methods. If you want the method you chose to be imported statically, press Alt+Enter and see what happens:
view all accessible classes
When you invoked Basic Completion (Ctrl+空格) in Java and didn't find your desired class in the list, it means that it's not yet imported in current file. Pressing Ctrl+空格 once more to view all accessible classes.
suggest to convert Smart-type Completion result using toArray() call
Pressing the same shortcut after you have invoked Smart-type Completion when an array type is expected will search for collections with same component type and suggest to convert them using toArray() call.
sorting completion variants by relevance or alphabetically
You can switch between sorting completion variants by relevance or alphabetically by using an icon at the bottom right:
Postfix code completion
Postfix code completion is applied "from right to left" and lets you avoid backward caret jumps when coding. After the code fragment that you want to change, type a dot (
.
), optionally pressCtrl+J
and select the desired option.
Scratch files
Scratch files allows you experiment and prototype right in the editor, without creating any project files.
To create a scratch file, press Ctrl+Alt+Shift+Insert, and then select its language.
changed a live template
If you've changed a live template, it becomes blue. If you want to return to the original text, right-click such a blue template, and choose
Restore defaults
on the context menu.
Add several cursors to your editor
在编辑器中添加多个光标
Add several cursors to your editor. To do that, press Ctrl twice and hold the key, and then press the arrow keys.
On Mac use Alt instead of Ctrl.
Clone the cursor
Clone the cursor strictly upwards or downwards. To do that, press
Ctrl+Shift+A
, typeClone caret
, and then choose the desired action.
view quick documentation when choosing a live template
When choosing a live template from a suggestion list, press Ctrl+Q to view quick documentation - to be sure you make a right choice:
launch the embedded local terminal using keyboard only
键盘启动本地终端
Android Studio makes it possible to launch the embedded local terminal using keyboard only. Press Alt+F12, and see the terminal running.
Make your printoutsnice and informative with the help of keywords
Make your printouts (File | Print) nice and informative with the help of keywords.
For example, use $DATE$ and $TIME$ to specify the exact date and time of the printout.
show documentation for a lookup item
When in a Code Completion lookup, press
Ctrl+Q
to show documentation for a lookup item, including class constructors.
So doing, if a class has more than one constructor, the links are shown:
Following a link shows documentation for the selected constructor.
Differences viewer
Have you noticed the buttons >><< marking differences in the Differences viewer?
You can simply apply differences between panes, by clicking one of these chevron buttons.
Keep theCtrl
key pressed, and the chevron buttons change to . Click one of these buttons to append contents of the current pane of the Differences viewer to the other pane.
If you keepShift
pressed, the chevrons turn into X. Click this button to revert changes.
code lens
Hover your mouse pointer over a warning, error stripe or just some section of source code on the scroll bar outside of the scroll box, and you will see a lens:
If the lens annoys you, get rid of it by clearing the check box on the context menu of the code analysis marker:
select multiple fragments in the "column mode"
在"列模式"
中选择多个片段:按Ctrl + Alt + Shift
(Cmd+Alt+Shift
on Mac)拖动鼠标即可。 感觉用不用Ctrl没区别
。
To select multiple fragments in the "column mode", keep
Control+Alt+Shift
(on Windows and Linux) orCmd+Alt+Shift
(on MAC), and drag your mouse cursor:
select multiple fragments of text
选择多个文本片段
:按Alt + Shift
拖动鼠标即可。
You can easily select multiple fragments of text. To do that, it's enough to keep
Alt+Shift
and drag your mouse cursor:
select multiple words
选择多个词:按Alt + Shift
后双击鼠标左键
选择词即可。
To select multiple words, press
Alt+Shift
, place the caret at each word to be selected and double-click the left mouse button.
Show quick doc on mouse move
鼠标移动时显示快速文档
:不需要显式地调用快速文档(Ctrl + Q
),只将鼠标指针移动到所需的符号,快速文档弹出窗口即自动显示。
要启用此功能,选中Settinigs | Editor
中Show quick doc on mouse move
复选框即。
You don't need to invoke quick documentation explicitly (
Ctrl+Q
) - if you just move your mouse pointer over the desired symbol, the quick documentation pop-up window will show automatically.
To enable this feature, select the check boxShow quick doc on mouse move
in the editor settings.
see all the available scratch files
查看所有可用的暂存文件
:在项目工具窗口
中选择Scratches
视图
To see all the available scratch files, choose Scratches view in the Project tool window.
copy rich text
富文本复制
:确保选中了Settinigs | Editor | Genernal
页面中的对应复选框即可。
Did you know that it's possible to copy rich text ?
Make sure that the check boxCopy rich text by default
in the General page of the Editor settings/preferences is selected:
generated automatically
生成自动声明
:当前文件中存在未声明的命名空间,按两次Ctrl+空格
调用的代码完成功能
可以完成XML标记名称。如果未声明命名空间,则会自动生成声明。
A special variant of the Code Completion feature invoked by pressing
Ctrl+空格
twice allows you to complete XML tag names from namespaces not declared in the current file. If the namespace is not declared yet the declaration is generated automatically.
coding assistance for SQL
SQL代码助手
:可以将SQL注入到字符串文字(Alt + Enter | Inject language or reference | <SQL dialect>
),然后使用SQL编码帮助。
You can inject SQL into a string literal (
Alt+Enter | Inject language or reference | <SQL dialect>
) and then use coding assistance for SQL.
优化引用
Ctrl + ALT + O
优化引用(Optimize Imports
),可以删除无用的引用。
删除无用资源
(Studio2.1+)Shift + Ctrl + Alt + I
弹出输入框,输入 Unused Resources
回车确认搜索后,点击Remove All Unused Resources
删除所有无用资源。
Android Lint 还有其他更强大的功能。
参考:
Idea快捷键(光标定位/切换/查找相关)
禁用系统的Ctrl+Alt+Left/Right(方向键)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。