A good developer knows how to write an efficient code but an awesome developer knows how to write that efficient code more efficiently. Today in this post, I will list some important and useful Android Studio shortcuts which, when used will save a significant amount of your time. I use these shortcuts and hence know the importance and the amount of time that it saves. And more importantly, they just let you code consistently without any breach of moving to your touchpad and looking for that option. All that you would need to use while coding will be your fingers and a few combination of keys. And I can assure you that you will enjoy coding your app using these cool shortcuts.
1. Live Templates
Windows/Linux: Ctrl + J
Mac: Cmd + J
With the help of Live Templates, you can easily eliminate writing boilerplate code by using shortcuts for specific things. On using the above shortcut, you will see a list of all the live templates you can use and by clicking on any of them, the IDE will write the code for the functionality shown. And when you know the names of these live templates, you can just write the name and press tab and see the magic. For example, the code for the live template for showing a toast message is “Toast”. Hence write Toast and press tab and woohoo!! You didn’t have to write the entire line for creating a toast message. You can even create your own live template by navigating to File > Setting > Editor > Code Style > Live Templates
2. Search for Command
Windows/Linux: Ctrl + Shift + A
Mac: Cmd + Shift + A
Using the above shortcut you can create a lot of things quickly without wasting your precious time. For example, if want to create a basic Java Activity, press Cmd + Shift + A in mac and then type “basic activity” and select the option that shows and press enter. A prompt will open asking you to name the activity and a new Java file will be created.
Windows/Linux: Alt + J
Mac: Ctrl + G
Using the multicursor shortcut, you can select a particular block or line of code and on pressing Ctrl + G on mac, it will select the next iteration where that code appears and again pressing the shortcut, you can further continue the selection as shown below. This can be useful when you want to rename all the iterations of a particular variable or other code.
4. Open a Class
Windows/Linux: Ctrl + N
Mac: Cmd + N
Use this shortcut and start typing any class name. It will show you the list of classes, select the one you intend to open and press enter.
5. Open any File
Windows/Linux: Ctrl + Shift + N
Mac: Cmd + Shift + N
Use this shortcut and start typing any file name. It will show you the list of filenames, select the one you intend to open and press enter.
6. Go to declaration
Windows/Linux: Ctrl + B
Mac: Cmd + B
Place the cursor on the variable and use this shortcut to see its declaration. Mostly, I use this when I want to change the data type of the declared variable or modify the structure of the class.
7. Move between tabs
Windows/Linux: Alt + Left Arrow Key/Right Arrow Key
Mac: Cmd + Shift + [ / ]
Use this shortcut to navigate between the open tabs in Android Studio. Just remember me and this shortcut when you feel lost among the sea of tabs open in front of you.
8. Move between design/text tabs in layout view
Windows/Linux: Alt + Shift + Left Arrow Key/Right Arrow Key
Mac: Ctrl + Shift + Left Arrow Key/Right Arrow Key
Use this shortcut to navigate between design and text tabs in layout view while editing XML files. This is probably the most used and time-saving shortcut when you are designing a layout.
9. Close a current tab
Windows/Linux: Ctrl + F4
Mac: Cmd + W
Use this shortcut to close a currently opened tab in Android Studio. It will close the tab that is currently selected.
10. Format/Indent the Code
Windows/Linux: Ctrl + Alt + L
Mac: Cmd + Option + L
Use this shortcut to auto-indent or format the entire code in a given file.
11. Smart Code Completion
Windows/Linux: Ctrl + Shift + Space
Mac: Ctrl + Shift + Space
Use this shortcut to get a suggestion regarding the naming of your variables and methods.
Windows/Linux: Ctrl + F
Mac: Cmd + F
Use this shortcut to find anything in a given file. Nothing new but worth mentioning. 😐
13. Find and Replace
Windows/Linux: Ctrl + R
Mac: Cmd + R
Use this shortcut to find and replace anything in a given file. Of course, you know it but one ought not to leave anything out.
14. Move hardcoded Strings to Resources
Windows/Linux: Alt + Enter
Mac: Option + Return
Use this shortcut to convert and save your hardcoded strings into strings.xml file of resources folder.
15. Build and Run
Windows/Linux: Shift + F10
Mac: Ctrl + R
Use this shortcut to build your project and run it on the device or emulator.
16. Search Anything
Windows/Linux: Press Shift twice
Mac: Press Shift twice
Use this shortcut to search anything related to your project in Android Studio.
17. Generate Code
Windows/Linux: Alt + Insert
Mac: Cmd + N
Use this shortcut to generate code like getters, setters, constructors etc.
So, friends, this includes almost all most prominently used shortcuts in Android Studio. Feel free to add to the list. If I have forgotten some important one, I’ll definitely update this list.
Happy Coding.. (: