/ Android

Top 10 Android Studio keyboard shortcuts

Man is a tool-using animal. Without tools he is nothing, with tools he is all. - Thomas Carlyle

Thomas Carlyle was on the right path but his assessment applies even more so to programmers. We use tools constantly to make us better, more efficient Android Developers. As an Android Developer, our most used tool is our IDE, which in most cases is Android Studio. Android Developers that are not currently using Android Studio should be evaluating their current life choices as AS is an IDE designed specifically for Android Developers whereas Eclipse is a Java IDE with an Android plugin. This post will explore some of the keyboard shortcuts that you can use in Android Studio to make you an even more efficient developer.

  1. Complete statement - Ctrl + Shift + Enter (Ctrl + ;)
    Used to space out and complete conditional statements as well as to add a semicolon to the end of the current statement.
    {<1>}Android Studio complete statement

  2. Generate (Getters/setters) - Alt + Insert
    This one is pretty standard across various IDEs, basically it will generates getPrivateField() and setPrivateField(Object o) for which ever private fields you specify.
    {<2>}Android Studio Generate menu

  3. Go to declaration - Ctrl + B
    What this shortcut does depends on how it is called. If it is called on an instance variable, it will scroll to the point in the class where that variable was declared. If it is called on a class name, that class will open in the editor, even if Android Studio has to decompile the source to show it to you.

  4. Cast as type - Ctrl + Shift + Space
    This will cast a variable automatically which comes in handy when you are using findViewById(). It will be cast the View to whatever class the variable is.
    {<3>}Android Studio cast as type

  5. Find Usages -Alt + F7
    Using this will search the entire project for the query. It will show you all of the instances of the query, including import statements, variables and even classes that extend the query (if it was a class).

  6. Extract as

  • Constant - Ctrl + Alt + C
  • Field - Ctrl + Alt + F
  • Method - Ctrl + Alt + M

These shortcuts will turn any expression(s) into either a public static final constant, a local variable or a method.

Android Studio extract as method

  1. Parameters - Ctrl + P
    Once a method is selected, this will will show the parameters for that method and if the method is overloaded it will display a list of the possible parameters.
    {<4>}Android Studio parameters

  2. Search everywhere - Shift Shift
    This will look everywhere for the query and show you the results. Queries can include, classes, files, methods, settings and more.
    {<5>}Android Studio search everywhere

  3. Rename - Shift + F6
    This will update all occurrences of whatever is being renamed and it will show it in real time. Anything that can be named can also be renamed; classes, files, methods, variables and more.
    {<6>}Android Studio rename

  4. Surround with block comments - Ctrl + Shift + Slash
    This will take whatever is highlighted and surround it with block comments /* and \*.
    {<7>}Android Studio toggle block comments

This was meant as an introduction into the keyboard shortcuts that Android Studio supports out of the box. It was in no way an exhaustive list as some of the more common shortcuts were not included. If one of your favorites shortcuts wasn't included, feel free to drop us a comment and let the world know what keyboard shortcut is your favorite.