Android Studio 技巧

一、Help | Find Action (Ctrl + Shift + A),这个快捷键非常有用,是一个命令查找,在任何时间,都可以执行此命令,输入你需要的操作,例如”extract method”,下面会出现命令以及对应的快捷键。

二、提取方法 (Alt + Shift + M)

三、运行单个java文件:Alt + Shift + F10

四、创建新类:Double Shift / Ctrl + Shift + A -> new java class

五、Android Studio使用技巧系列教程(-)

六、Android Studio for Experts:Edit & Debug & Test

1. Completion(代码补全):Ctrl + Alt + Space / Ctrl + Space / Shift + Alt + Space (Code Completion),Tab覆盖补全

2. Replace Structurally(自定义结构体替换) / Replace in Path / Search Structually :Ctrl + Shift +A -> Replace Structurally

3. Designtime Attributes(设计时属性,编译时自动过滤):tools:showIn,tools:listitem,tools:visibility,tools:text...

4. Public and Private Resources:Android studio 默认 library 的所有 resource 为 public,未添加的视为私有的。

<public name="mylib_app_name" type="string"/>

5. Analyze Stacktrace(查看Bug Report,可点击定位到出错代码位置):Analyze → Analyze Stacktrace 或者搜索 Analyze Stacktrace

6. Evaluate Expression(Debug模式下计算自定义表达式结果):查找或者右击进入

7. Break Point:

  可以在断点上右击,给断点加上生效条件;或者设置断点不是 suspend,而是打印一些信息

  异常断点:Run -> View BreakPoints -> [+] -> Exception Breakpoint

8. 视频:Android Studio for Experts (Android Dev Summit 2015)(英文字幕)

9. 相关:Android Studio for Experts(GithubGist)

七、查看文件/类结构(Ctrl + F3):查看当前类下的成员变量/方法。

八、重命名(Alt + Shift + R):重命名文件/类/方法/变量,相关信赖也会被同步修改。

九、方法生成器(Alt + Insert):生成构造方法/Getter、Setter方法/重写基类方法。

十、关闭当前窗口/标签(Ctrl + F4):在标签栏点击 (Shift + 鼠标左键) 也有同样效果。关闭所有打开标签页(Ctrl + Shift + F4)。

十一、查看类/方法继承(Ctrl + T):查看实现/重写当前方法/类的地方。

十二、定位上次修改(Ctrl + Q):光标快速定位至上次代码编辑的位置,连续使用会继续定位至历史编辑的位置。

十三、最近访问文件列表(Ctrl + E):列出最近访问的文件列表。

十四、Live Templates提示(Ctrl + Alt + Shift + J):可以快速补全。

十五、定位代码错误(Settings | Keymap | Next Highlighted Error):光标定位至当前类代码错误/高亮警告的位置。

十六、定位至块开始/结束(Ctrl + { ):光标定位至方法块的开始/结束(Ctrl + } )。

十七、提取内部类为外部类(Shift + Alt + V):移动内部类为外部类,或者重命名为外部类。

十八、提取匿名内部类为本地变量(Shift + Alt + V):提取匿名内部类,并命名本地对象名称。

十九、自动补全并修正结构体(Shift + Alt + L):if, do-while, try-catch, return等。

------------------------------------------ Live Templates ---------------------------------------------

Live Templates: Ctrl + Shift + A (搜索:insert Live Template,或者 Ctrl + Alt + Shift + J)

  Live templates are stored in the following location: ~/.AndroidStudio1.4/config/templates

  Windows: <your home directory>.<product name><version number>config emplates
  Linux: ~/.<product name><version number>/config/templates (e.g: ~/.AndroidStudio1.4/config/templates)
  OS X: ~/Library/Preferences/<product name><version number>/templates

  1. Android Studio for Experts(Android Dev Summit2015)

  2. Android Studio for Experts:Edit & Debug & Test

  3. Android Studio Live Templates  // How to define your own live templetes

  4. 使用Android Studio快捷键提升效率

  5. idea-live-templates

  // Method Block 

  for: for (String s : list) {}  // foreach

  fori: for (int i = 0; i < list.size; i++) {}  // 正序for

  forr: for (int i = list.size(); i >= 0; i--) {}  // 逆序for

  lazy: if (lazy == null) { lazy = new Lazy();}

  ifn: if (* == null) {}

  inn: if (* != null) {}

  fixme: "// FIXME: 2015-12-20"

  todo: "// TODO: 2015-12-20"

  rouiT: // runOnUIThread

  fbc: (*) findViewById(R.di.*);

  visible: *.setVisibility(View.VISIBLE);

  gone: *.setVisibility(View.GONE);

  rgC: *.getColor(R.color.*);

  Toast: Toast.makeText(Demo.this, "*", Toast.LENGTH_SHORT).show();

  rgS: *.getString(R.string.*);

  Sfmt: String.format("*", );

  souf: System.out.prinf("");

  sout: System.out.println();

  soutv: System.out.println("* = " + *);

  soutp: // Prints method parameter names and values to System.out

  serr: System.err.println("");

  St: String

  logm: // Log method name and its arguments

  logr: // Log result of this method

  // Class Block

  const: private static final int * = 343;

  St: String

  psf: public static final *

  psfi: public static final int *

  psfs: public static final String * 

  geti: public static ClassName getInstance() { return *; }

  noInstance: private ClassName() {// no instance}

  newInstance: public static ClassName newInstance() {Bundle args = new Bundle();    ClassName fragment = new ClassName();    fragment.setArguments(args);    return fragment;}

  psvm: public static void main(String[] args) {}

  ViewConstuctors: // Adds generic view constructors

  Parcelable: // Create a parcelable block for your current class

  logd / logi / logw / loge: Log.d(TAG,"*: *");

  logt: private static final String TAG = "ClassName"; 

  // MORE: 自定义 [+]

原文地址:https://www.cnblogs.com/veins/p/4465358.html