Android Studio tips & tricks -Part 1(for beginners)
It doesn’t matter how powerful the weapon unless you knew how to use at its best. We as developers are fortunate to have a powerful tool like Android Studio, thanks to google but you should know how to use it productively.
In the process of learning how to be efficient with studio first thing I learn is to reduce the usage of the mouse while coding, So this article is about the basic shortcuts that any Android developer should know.
1.Basic code suggestions
You don’t need to type everything while you’re using the android studio, For example, you need to write TextView then type Text and press Ctrl + space there you will see respective suggetions. These suggestions aren’t any class or layout specific, suggestions will be provided at the project level.
Windows: ctrl + space
Mac : cmd + space
2. Find anything in the project
For example, if your searching for a class, layout file, drawable, etc literally anything in the project just simply double click shift and type the file name.
Windows: double click shift
Mac : double click shift
3. Import libraries easily
For example, when you copy paste the code some libraries won’t import so that will result in errors, then place the cursor on that error and press alt + enter if their any libraries that aren’t imported will import now.
Windows: alt + enter
Mac : option + enter
4. Find anything in the active tab (class, layout, drawable)
Press ctrl + F and type what you’re looking for, there will arrows beside the word you’re the type to see how many occurrences of that word in the active tab. Have a look
Windows: ctrl + F
Mac : cmd + F
5. Find & Replace anything in active tab
Press ctrl + R then type the old word
Click the tab button and type the new word
Click Replace to replace on current selector you can replace all occurrences of that word by clicking on replace all option
Windows: ctrl + R
Mac : cmd + R
6. Format the code
If the code appears with uneven spaces or lines just press ctrl + alt + l to format.
Windows: ctrl + alt + l
Mac : cmd + option + l
7. Close active tab
To close active tab press ctrl + F4
Windows: ctrl + F4
Mac : cmd + w
8. Go to specific line number
Press ctrl + g and type the line number to want jump and press enter.
Windows: ctrl + G
Mac : cmd + L
9. Return to editor window
Android studio usually shows suggetions in a tool window, there will be times when you want to hide that window and get back to editor for that just press Esc
Windows: Esc
Mac : Esc
10. Jump to source
If you want to see the source of a resource file string, drawable, color, anything in the project just press ctrl + mouse left click on that resource.Have a look
Windows: alt + mouse left click
Mac : cmd + down arrow
11. Move between tabs
To switch between tabs press alt + right/left arrow based which side you want to switch
Windows: alt + left/right arrow
Mac : cmd + left/right arrow
12. Move between Design / Text tabs
In layout’s file to switch between text and design format click alt + shift + right/left arrow
Windows: alt + shift + left/right arrow
Mac : cmd + left/right arrow
13. New window
press shift+F4 to open active tab in new window.
Windows: shift + F4
Mac : shift + F4
14. Show/Hide line numbers
Mouse right click on the left edge of editor which results in a popup with option show line number. Have a look
15. Increase and Decrease character size in editor
Click File -> Settings -> General
Then you will see the option to change font size(Zoom) with Ctrl+Mouse Wheel
16. Move hardcoded strings to resources
Place the cursor on hardcoded string and press alt + enter then type a name for the string in resource files. Have a look
Windows: alt + enter
Mac : cmd + N
17. Collapse Method Body
As time passes project will grow so does the methods in the classes. In such times it would be hard to go through the code where this tip comes to rescue, to collapse specific method press ctrl + minus and to collapse all the methods press ctrl + shift + minus
Specific method
Windows: ctrl + minus
Mac : cmd + minus
All methods
Windows: ctrl + shift + minus
Mac : cmd + shift + minus
18. Expand Method Body
As time passes project will grow so does the methods in the classes. In such times it would be hard to go through the code where this tip comes to rescue, to collapse specific method press ctrl + plus and to collapse all the methods press ctrl + shift + plus
Specific method
Windows: ctrl + plus
Mac : cmd + plus
All methods
Windows: ctrl + shift + plus
Mac : cmd + shift + plus
19. Usage of REGION in Studio
As we collapsing the body of all methods will result to only specific level of clarty of the code but with REGION you will fully organize the code to the extact where normal person can also understand the codeing formate. Have a properly look on how to implement REGION
20. Choose from the last copy/pastes (manage your clipboard)
Press ctrl + shift + v which results in a popup with the history of clipboard default of 5 commands.Have a look
Windows: ctrl + shift + V
Mac : cmd + shift + V
21. Override methods
Place the cursor on the object and press ctrl + O
to override methods from specific class or anything else.
Windows: ctrl + O
Mac : ctrl + O
These are some of the basic tips which i use on dialy basis, On my next article we will discuss even more useful tips.Thank you for reading
If you like my article, please don’t forget to click 👏👏👏 & to recommend it to others 👏👏👏.
Also, to be notified about my next articles and stories, follow me on Medium.