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.
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.
Generate (Getters/setters) -
Alt + Insert
This one is pretty standard across various IDEs, basically it will generates
setPrivateField(Object o)for which ever private fields you specify.
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.
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
Viewto whatever class the variable is.
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).
- 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.
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.
Search everywhere -
This will look everywhere for the query and show you the results. Queries can include, classes, files, methods, settings and more.
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.
Surround with block comments -
Ctrl + Shift + Slash
This will take whatever is highlighted and surround it with 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.