http://www.developerphil.com/android-studio-tips-of-the-day-roundup-2/


This is the second roundup of my Android Studio Daily Tips that I post onGoogle+
You can take a look at the previous posthere.

About Keymaps

Android Studio provides different keymaps (the mapping between shortcut keys and an action). You can see which keymap you are using inSettings->Keymap.

It wouldn’t be practical to list the shortcuts for every keymap so the following will be used:

  • Windows: Default
  • Linux: Default
  • OSX: Mac OSX 10.5+

Duplicate Lines

cmd+d ctrl+d

Just as it says: it will copy the current line and paste it below without interfering with your clipboard. It can be pretty useful when it’s used with the move line shortcut!

Expand/Shrink Selection

alt+up/down ctrl+w / ctrl+shift+w

This will contextually expand the current selection. e.g. it will select the current variable, then the statement, then the method, etc.

Surround with

cmd+alt+t ctrl+alt+t

This can be used to wrap a block of code in some structure. Usually an if statement, a loop, a try-catch or a runnable.

If you have nothing selected, it will wrap the current line.

Recents

cmd+e ctrl+e

Using this, you get a searchable list of the most recently consulted files!

Live Templates

cmd+j ctrl+j

The live template is a way to quickly insert a snippet of code. The interesting thing with live templates is that they can be parameterized with sensible defaults and guide you through the parameters when you insert it.

Additional Tip:

  • You don’t need to invoke the shortcut if you know the abbreviation. You only need to type it and complete using theTabkey.

Move Methods

cmd+alt+up/down ctrl+shift+up/down

This is like theMove Lineshortcut but applied to whole methods. It allows you to move a method below or above another one without copy-pasting.

The real name of this action isMove Statement. Meaning that it moves any kind of statement. E.g. you can reorder fields and inner classes.

Complete Statement

cmd+shift+enter ctrl+shift+enter

This will generate the missing code to complete a statement The usual use cases are:

  • Add a semicolon at the end of the line, even if you are not at the end of the line
  • Add the parentheses and curly braces after an if, while or for
  • Add the curly braces after a method declaration

Additional Tip:

  • If a statement is already completed, it will go to the next line even if you are not at the last character of the current line.

Last Edit Location

cmd+shift+backspace ctrl+shift+backspace

This will make you navigate through the last changes you made. This is different from clicking the back arrow in the toolbar in that it makes you travel within your edition history and not your navigation history.

Join Lines and Literals

ctrl+shift+j ctrl+shift+j

This is doing more than simulating the delete key at the end of the line! It will preserve formatting rules and it will also:

  • Merge two comment lines and remove the unused //
  • Merge multiline strings, removing the + signs and the double-quotes
  • Join fields and assignments

Additional Tip:

  • If you select a string that spans multiple lines, it will merge it on a single one.

Select In

alt+f1 alt+f1

Takes the current file and asks you where to select it. The most useful shortcuts IMHO are to open in the project structure or in your file explorer. Note that each action is prefixed by a number or a letter, this is the shortcut to invoke it quickly.

Usually, I’ll go Alt+F1 then Enter to open in the project view and Alt+F1+8 to reveal the file in Finder on the Mac.

You can invoke this from a file or directly from the project view.

Unwrap/Remove

cmd+shift+delete ctrl+shift+delete

This will remove the surrounding code. It could be to remove an if statement, a while, a try/catch or even a runnable. This is exactly the opposite of theSurround Withshortcut.


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 阅读《Android(安卓)从入门到精通》(12)—
  2. Android(安卓)EditText相关
  3. android内部类广播(本地广播)BroadcastRece
  4. 用android编写颜色立方体
  5. android 入门demo 事件监听
  6. smartq7 android 内核显示启动信息
  7. 【Android】【应用信息】获取服务列表
  8. android 调用本地音乐播放器
  9. android典型代码系列(二十五)------popup
  10. android opengl es 七彩星星效果