studio 快捷键

来源:互联网 发布:github tensorflow 编辑:程序博客网 时间:2024/06/11 23:51

注释代码(反注释代码):

  • Ctrl+L

代码格式化

  • Win/Linux下: Ctrl + Alt + L
  • Mac: Option + Command + L

导入相应的包申明 import :

  • Alt+Enter  (注意:在xml中是提取资源,如从布局文件中提取字符串到strings.xml文件中
 

定位代码修改处

 

(Navigate | Last Edit Location) brings you back to the last place where you made changes in the code.

 

 

Pressing Ctrl+Shift+Backspace a few times moves you deeper into your changes history.

 

 

  • Ctrl+Shift+Backspace

 

查看最近常编辑的文件:

  • Ctrl+E

 

 

跳转到语法错误

Use F2/Shift+F2 keys to jump between highlighted syntax errors.

 

  • F2/Shift+F2

 

Use Ctrl+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 choose Go to high priority problems only.

从剪切板中粘贴最近剪切复制的内容:

 

  • Ctrl+Shift+V

 

 

生成方法注释

先输入 “/**” ,然后回车,就会自动加上 Parameters关键字。

 

 

获取帮助:

快捷键:ctrl+shift+A  ,输入关键字。
或者是 Help——find action

 

 

编辑快捷键

捷键解释Ctrl + SpaceBasic code completion (the name of any class,method or variable)Ctrl + Shift + SpaceSmart code completion (filters the list of methods and variables by expected type)Ctrl + Shift + EnterComplete statementCtrl + PParameter info (within method call arguments)Ctrl + QQuick documentation lookupShift + F1External DocCtrl + mouse over codeBrief InfoCtrl + F1Show descriptions of error or warning at caretAlt + InsertGenerate code… (Getters, Setters, Constructors, hashCode/equals, toString)Ctrl + OOverride methodsCtrl + IImplement methodsCtrl + Alt + TSurround with… (if..else, try..catch, for, synchronized, etc.)Ctrl + /comment注释/反注释一行代码commentCtrl + Shift + /注释/反注释代码段commentCtrl + WSelect successively increasing code blocksCtrl + Shift + WDecrease current selection to previous stateAlt + QContext infoAlt + EnterShow intention actions and quick-fixesCtrl + Alt + LReformat code格式化代码Ctrl + Alt + OOptimize imports导入Ctrl + Alt + IAuto-indent line(s)Tab / Shift + TabIndent/unindent selected linesCtrl + X or Shift + DeleteCut current line or selected block to clipboardCtrl + C or Ctrl + InsertCopy current line or selected block to clipboardCtrl + V or Shift + InsertPaste from clipboardCtrl + Shift + VPaste from recent buffers…Ctrl + DDuplicate current line or selected blockCtrl + YDelete line at caretCtrl + Shift + JSmart line joinCtrl + EnterSmart line splitShift + EnterStart new lineCtrl + Shift + UToggle case for word at caret or selected blockCtrl + Shift + ] / [Select till code block end/startCtrl + DeleteDelete to word endCtrl + BackspaceDelete to word startCtrl + NumPad+/-折叠/展开代码块Expand/collapse code blockCtrl + Shift + NumPad+展开所有代码块Expand allCtrl + Shift + NumPad-折叠所有代码块Collapse allCtrl + F4Close active editor tabCtrl + Shift + CCopy PathCtrl+ Alt + Shift + CCopy Reference

Ctrl + Period(句号)将指针放入方法体中,代码折叠或展开        

打开粘贴复制面板:

ctrl+shift+v
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.

search and replace

快捷键解释Double ShiftSearch everywhereCtrl + F查找FindF3Find nextShift + F3Find previousCtrl + R替换ReplaceCtrl + Shift + F查找Find in pathCtrl + Shift + RReplace in pathCtrl + Shift + SSearch structurally (Ultimate Edition only)Ctrl + Shift + MReplace structurally (Ultimate Edition only) 

 

 

Usage search

 

快捷键解释Alt + F7 / Ctrl + F7Find usages / Find usages in fileCtrl + Shift + F7Highlight usages in fileCtrl + Alt + F7Show usages

 

 

 

Compile and Run

 

快捷键解释Ctrl + F9Make project (compile modifed and dependent)Ctrl + Shift + F9Compile selected file, package or moduleAlt + Shift + F10Select configuration and runAlt + Shift + F9Select configuration and debugShift + F10RunShift + F9DebugCtrl + Shift + F10Run context configuration from editor 

 

 

Debugging

 

快捷键解释F8Step overF7Step intoShift + F7Smart step intoShift + F8Step outAlt + F9Run to cursorAlt + F8Evaluate expressionF9Resume programCtrl + F8Toggle breakpointCtrl + Shift + F8View breakpoints 

 

 

Navigation

 

快捷键解释Ctrl + N跳转到制定的类中,包括内部类Ctrl + Shift + NGo to fileCtrl + Alt + Shift + NGo to symbolAlt + Right/LeftGo to next/previous editor tabF12Go back to previous tool windowEscGo to editor (from tool window)Shift + EscHide active or last active windowCtrl + Shift + F4Close active run/messages/find/… tabCtrl + G跳转到指定行Ctrl + E打开最近编辑的文件界面Ctrl + Alt + Left/RightNavigate back/forwardCtrl + Shift + BackspaceNavigate to last edit locationAlt + F1Select current file or symbol in any viewCtrl + B or Ctrl + Click跳转到变量、方法、类的声明的地方Ctrl + Alt + BGo to implementation(s)Ctrl + Shift + IOpen quick definition lookupCtrl + Shift + BGo to type declarationCtrl + UGo to super-method/super-classAlt + Up/DownGo to previous/next methodCtrl + ] / [Move to code block end/startCtrl + F12File structure popupCtrl + H类的层次Type hierarchyCtrl + Shift + HMethod hierarchyCtrl + Alt + HCall hierarchyF2 / Shift + F2Next/previous highlighted errorF4 / Ctrl + EnterEdit source / View sourceAlt + HomeShow navigation barCtrl + F11Toggle bookmark with mnemonicCtrl + #[0-9]Go to numbered bookmarkShift + F11Show bookmarks 

move移动代码的快捷键:

 

实例:快速跳转到某个class文件的指定行

方法:先按Ctrl + Shift + N ,然后输入你要打开的类的名字(不一定要完整输完),直到匹配唯一,然后在后面加上 “ :行数”

Refactoring

快捷键解释F5CopyF6MoveAlt + DeleteSafe DeleteShift + F6RenameCtrl + F6Change SignatureCtrl + Alt + NInlineCtrl + Alt + MExtract MethodCtrl + Alt + VExtract VariableCtrl + Alt + FExtract Field  ,提取变量,以改变其初始化的位置Ctrl + Alt + CExtract ConstantCtrl + Alt + PExtract Parameter Alt + Enter在xml中是提取资源,如从布局文件中提取字符串到strings.xml文件中
 

Refactoring Code

快捷键: Ctrl+Alt+Shift+T | Ctrl+T

 

Change Signature

修改方法的签名,如可见性,返回值等 快捷键: ctrl+F6

Type Migration

As the name suggests, type migration allows you to migrate from one Java type to another.
Let’s assume that you create a Person class. Further along in your development, you discover
that Person is too generic, so you create a Manager class that extends Person. If you want to
migrate all instances of Person to Manager, you can do this easily with type migration.Place your cursor on the String declaration (highlighted in bold in the following code
snippet) of the greetings method and press Ctrl+Shift+F6 | Cmd+Shift+F6 or choose
Refactor ➤ Type Migration. The resulting dialog box resembles that seen in Figure 4-4.
public String greetings(String greet){
    return "Hello " + greet;
} 

Move 移动文件

Refactor——move 或者是 F6 到指定的包中

Copy 文件

与move文件类似,Refactor——copy 或者是 F5
Safe Delete删除文件
delete键 或者  Refactor——delete 

Extract Variable

根据构造函数,自动生成变量名声明,快捷键为:Ctrl+Alt+V
51-extractvariable.gif

Extract Constant

快捷键:Ctrl+Alt+C
As you develop apps in Android, you will find yourself using a lot of Strings as keys—for
example, in Maps and Bundles. Therefore, extracting constants will save you a lot of time.
Define a method like the one seen in the following code snippet. Place your cursor anywhere on the name_key string and press Ctrl+Alt+C | Cmd+Alt+C. The resulting dialog box should look like Figure 4-9. Here, Android Studio provides a few suggestions for names. By convention, constants in Java are all caps. Select NAME_KEY and press Enter.
private void addName(String name, Bundle bundle ){
    bundle.putString("name_key", name);
}
You should end up with a constant called NAME_KEY, which should be defined like this:
public static final String NAME_KEY = "name_key";

Extract Field

自动指定声明变量和初始化的位置,快捷键: Ctrl+Alt+F
如:现定义如下方法:
private Date getDate(){
return new Date();
}
然后按Ctrl+Alt+F ,就可以指定初始化和声明的位置:

Extract Parameter

根据代码,生成方法的参数 ,快捷键: Ctrl+Alt+P
Extract Parameter allows you to extract a variable and place it as a parameter of the enclosing method. Define a method in your Sandbox class:
private void setDate(){
         mDate = new Date();    
}
Place your cursor anywhere on Date() (highlighted in bold), press Ctrl+Alt+P | Cmd+Alt+P,
and press Enter. The resulting method should look like the following code snippet:
private void setDate(Date date){
        mDate = date;        
}
52-extractparam.gif

Extract Method

将某些代码块放到一个新的方法中 ,快捷键: Ctrl+Alt+M
53-extractmethod.gif

Push Members Down and Pull Members Up

将子类的变量放到父类中,快捷键:ctrl+alt+shift+T ,选择Push Members Down/Pull Members Up 。

When we talk about pulling something up, we mean that we will take something in the current class (usually a method or a field) and send it to the parent class or interface.

If the parent is a class, the content will be moved. If the parent is an interface, it will declare the method as part of the interface, keep the method in your class and add the @override annotation.

When we talk about pushing members down, that is exactly the opposite operation, we are sending content from the parent class/interface in the child class.

Replace Inheritance with Delegation

当想修改继承关系的时候,将继承替换为 父类为当前类的一个filed属性 。
Right-click (Ctrl-click on Mac) the com.apress.gerber.helloword package and choose
New ➤ Java Class. Name your class Patio and make it extend Sandbox:
public class Patio extends Sandbox {
     
}
Upon further analysis, we decide that Patio is not a Sandbox, but rather has a Sandbox. To
change this relationship, navigate to Refactor ➤ Replace Inheritance with Delegation. In the
resulting dialog box, click the Generate Getter for Delegated Component check box, shown
in Figure 4-14.
Your Patio class should now have a Sandbox member, as shown in the following code snippet:
public class Patio {
 
    private final Sandbox mSandbox = new Sandbox();
 
    public Sandbox getSandbox() {
        return mSandbox;
    }
}

Wrap Method Return Value

Wrapping a return value may be useful when you need to return an object rather than a primitive (though there are other scenarios where you might want to wrap a return value). 
Place your cursor on the getChildren() method and navigate to Refactor ➤ Wrap Method Return Value. Select the Use Existing Class check box and type java.lang.Integer as the Name and value as the Wrapper Field, as shown in Figure 4-16. Now click Refactor and notice that your getChildren() method returns an Integer object rather than a primitive int.

Replace Constructor with Factory Method

快捷键: Alt+Insert
Place your cursor inside the enclosing brackets of the Sandbox class definition. Press Alt+Insert | Cmd+N and select Constructor to generate a new constructor. Choose both members, shown in Figure 4-17, and click OK.
Place your cursor anywhere in the newly defined constructor, shown in the following code
snippet, and then navigate to Refactor ➤ Replace Constructor with Factory Method. The
resulting dialog box looks like Figure 4-18. Click Refactor to generate a factory method.
public Sandbox(String shovel, int children) {
    mShovel = shovel;
    mChildren = children;
}
Notice that the constructor is now private and that a new static method returns an instance
of the Sandbox class, as shown in the following code snippet. This operation is particularly
useful if you are creating a singleton.
public static Sandbox createSandbox(String shovel, int children) {
     return new Sandbox(shovel, children);
}

Convert Anonymous to Inner

将匿名类转换为内部类:快捷键:Alt+Enter
In the constructor of your Sandbox class, add the following line:
new Thread(new Runnable()).start(); 
Place your cursor on Runnable() and press Alt+Enter to invoke the code-completion
operation. Then select Implement Methods. Select the run method and click OK. Your code
should look something like the following code snippet:
new Thread(new Runnable() {
       @Override
       public void run() {
           //do something
       }
   }).start();
 Place your cursor on Runnable() and navigate to Refactor ➤ Convert Anonymous to Inner.
Android Studio suggests MyRunnable as a class name for you, as shown in Figure 4-19.
Deselect the Make Class Static check box and click OK. Notice that you now have a private
inner class called MyRunnable in Sandbox.java that implements the Runnable interface. This
example doesn’t do much; however, you may have opportunities to use this operation when
delegating the behaviors of Views.

VCS/Local History

快捷键解释Ctrl + KCommit project to VCSCtrl + TUpdate project from VCSAlt + Shift + CView recent changesAlt + BackQuote (`)‘VCS’ quick popup
 

Live Templates

快捷键解释Ctrl + Alt + JSurround with Live TemplateCtrl + JInsert Live TemplateiterIteration according to Java SDK 1.5 styleinstCheck object type with instanceof and downcast ititcoIterate elements of java.util.CollectionititIterate elements of java.util.IteratoritliIterate elements of java.util.Listpsfpublic static finalthrthrow new 
 
实例:自动完成 for 语句
方法:按Ctrl + J ,然后选择"fori"
 
更多代码模版,见File——settings——Editor——Live Templates
 

General

快捷键解释Alt + #[0-9]Open corresponding tool windowCtrl + SSave allCtrl + Alt + YSynchronizeCtrl + Shift + F12Toggle maximizing editorAlt + Shift + FAdd to FavoritesAlt + Shift + IInspect current file with current profileCtrl + BackQuote (`)Quick switch current schemeCtrl + Alt + SOpen Settings dialogCtrl + Alt + Shift + SOpen Project Structure dialogCtrl + Shift + AFind ActionCtrl + TabSwitch between tabs and tool window 

界面快捷键

Using Code Generation

先进行优化设置:
 Click File ➤ Settings ➤ Code Style ➤ Java ➤ Code
Generation to bring up the Settings dialog box with the Code Generation tab selected. If the
Field and Static Field text boxes do not contain m and s respectively, type them there now
and click Apply and then OK, as shown in Figure 3-8.
这样当设置属性field(变量)的时候,使用类似规则:
public String mName;

 Code Generation  之  Constructors构造器

快捷键Alt+insert ,然后选择constructors ,默认的构造器是无参数的。如果想构造有参数的构造器,前提是你的类中有非final变量,然后当你用alt+insert产生构造器的时候,就有有个面板让你选择用哪些变量作为构造器参数:

 Code Generation 之 Getters/Setters

Alt+insert,选择 getter或者setter 。因为前面设置属性以m开头,所以当使用generation的getter,setter的时候,得到的方法名中不包含m前缀,如下图:

Code Generation 之 Override Methods

Alt+insert,选择 Override Methods .

Code Generation 之 Delegate Methods

Alt+insert,选择Delegate Methods。说白了就是调用父类的方法,当然你可以再自己修改下。
字面上翻译就是“生成代理方法”,就是如果你有一个类的属性,只要它不是基本类型(int, long, float...),就根据这个类型的所有父类型(包括接口)生成同名的方法,并调用父类型的方法。
这么解释起来有点抽象,你可以创建一个属性,比如
public class Test {
private String testStr; //在这个变量名上点右键“generate delegate methods"
...
你会发现所有String类以及父类Object类的所有方法都列出来了,你可以生成其中某个或全部方法的代理方法,例如生成length()方法的代理方法如下:
public int length() {
return testStr.length();
}
你可以看到”代理方法“一般只是简单的对父类型的同名方法做了调用,一般你还需要添加一部分功能,但是eclipse已经把重复劳动的那一部分替你做了。

 

Inserting Live Templates

  快速插入代码块:File——settings——Editor——Live Templates

快捷键为:
有时候也可以在Editor中,输入类似 psf之类的,就会出现代码块提示

Styling Your Code

File——settings——Editor——Code Style ——java

Surrounding With

将代码用if-else 或者try catch包围:
快捷键:

 

来自为知笔记(Wiz)
0 0