Sep 26, 2018 Android Studio takes care of all the formatting. Just Press CTRL+ALT+L on Windows or Command+Option+L on Mac. The android studio will reformat all the code for you. And the good part is that it.
- The Android Studio has an option where you can browse the dcoumentation quickly. It performed with the help of Ctrl + Q. Syntax: Windows: CTRL + Q Mac: CTRL + J CTRL + ALT + L - Reformat code: The Android Studio has an option where you can format the code with just one press. It performed with the help of Ctrl + Alt + L.
- Android studio change keyboard shortcuts, android studio import shortcut mac, android external keyboard shortcut keys, android studio keyboard.
- Android Studio provides keyboard shortcuts for many common operations. Table 1 shows the default keyboard shortcuts by operating system. Note: In addition to the default key mappings in Table 1 below, you can choose from a variety of preset key mappings or create custom key mappings.
Among many keyboard shortcuts, Android Studio provides a very useful context aware shortcut to manage intention actions: Alt+Enter (non Mac world) or Option+Enter (Mac world)
Prerequisites¶
Suggest improvements for your code¶
As you work in Android Studio, IntelliJ IDEA integrated development editor analyzes your code, searches for ways to optimize it, and detects potential and actual problems.
As soon as the IDE finds a way to alter your code, it displays a yellow bulb icon in the editor next to the current line. If a problem is detected it displays a red bulb icon instead and prompts you to select an associated fix.
The IntelliJ IDEA yellow bulb icon
The IntelliJ IDEA red bulb icon
The IDE highlights the possible improvements or errors with a squiggly red line, points unresolved references by changing font color to red, highlights old anonymous classes in grey, etc.
Placing the cursor on the red highlighted section and using Alt+Enter or clicking the bulb icon you can view available intention actions for this unit of code.
Depending on where your cursor is located when you use the shortcut you get a custom list of actions that makes your life easier.
There are many situations where you would be able to use this Alt+Enter or Option+Enter feature. Let's illustrate in Pepper app creation situations.
Add missing interface methods, the speedy way¶
Add RobotLifecycleCallbacks methods¶
When you create a new project for Pepper, remember you need to 'robotify' the project and implement RobotLifecycleCallbacks methods as described in Getting Started > Creating a Robot application lesson.
After adding the RobotLifecycleCallbacks
statement in your MainActivity file your code should look as follow:
❌Note that class MainActivity
will be underlined with a red squiggly line meaning there is an error. In fact you should implement the three functions of the RobotLifecycleCallbacks
interface which are onRobotFocusGained
, onRobotFocusRefused
and onRobotFocusLost
.
✔️ You can implement the 3 methods in 5 seconds using Alt+Enter instead of typing all these functions.
- Place the cursor wherever on the red squiggly underlined string
- Type Alt+Enter or Option+Enter
- Choose Implement methods in the contextual menu displayed
- On the window that pops up, select onRobotFocusGained, onRobotFocusLost and onRobotFocusRefused and validate clicking on 'Ok'
Here you are, you have quickly added the missing methods. Easy, isn't it?
Step by step animation
Contextual bulb¶
In addition to the use of Alt+Enter you can use the bulb that appears after a few seconds or typing Alt+Enter when you place the cursor on an underlined section of your code. Selecting the bulb the intentions menu is displayed with the same menus as with Alt+Enter.
Add import statements¶
Let's illustrate the use of the intention actions menu with another example. Android Studio automatizes many actions including the proper import
statements. However you may still need to add your own references to libraries.
Fix Unresolved reference¶
The Alt+Enter shortcut on android studio will help automatically fix 'Unresolved reference' error adding the import statements needed.
Don't go too fast¶
Be careful not to use Alt+Enter too fast. Some import
statements may not fit your needs.
As an example com.aldebaran.qi.sdk
has a Locale
object as java.util
library does. It is easy to mismatch when using Alt+Enter quickly. If you insert a wrong import statement, simply delete it and use Alt+Enter again.
❌ Erroneous import below, that will not work
✔️ Correct import below
Conclusion¶
There are many other useful intention actions available in Android Studio. They will help you to save time, speed up coding and take advantage of Android Studio rich environment.
Intention actions cover a wide range of situations from warnings to optimization suggestions. You can view the full list of intention actions and customize them in the Settings/Preferences dialog (File > Settings > Editor > Intentions).
How to browse list of actions and corresponding shortcuts¶
You can easily access the list of actions and the corresponding shorcut if any. To do so use the shortcut Ctrl+Shift+A
or Cmd+Shift+A
(Mac world). In the field of the popup, type the word you look for. Type make and you'll get the action Make project in the list with the shortcut associated Ctrl+F9
display right next to it.
Nice isn't it ?
Android Studio is a most popular and widely used IDE by Android Developers. Research shows that programmers who uses Keyboard Shortcut keys while developing applications are more productive and generates faster output than programmers who uses mouse often for all tasks. Android Studio Keyboard Shortcuts are very well managed.
Using Android Studio Keyboard Shortcuts like autocomplete, code generation, snippets and many more will definitely increase your speed. So first question in your mind might be
Why we should actually know android studio keyboard shortcuts?
- Efficiency:
It is generally acknowledged by Pro Programmers that you can increase productivity and accomplish more tasks by using the keyboard instead of mouse. In other words, it’s easier and gets your job done faster:). For Example if you want to write getter and setter for all the variables of the class. Than it might be time consuming where android studio provides keyboard shortcut for it.
- Complementarity :
You can take advantage of using keyboard and mouse. Take example like you want to copy some code at the same time you want to also navigate from classes. You can use mouse to navigate between classes and keyboard shortcut for copy and pasting.
- Multitasking:
Definitely you will become multitasking. If you use android studio keyboard shortcuts you don’t need to check mouse pointer to see what you are doing and you can do that thing semi-automatically thus freeing your mind for other tasks.
Those are the points which i consider as a productive programmer.
As an Android Developer i am going to consider only Android Studio and here i will mention useful
Android Studio Keyboard Shortcuts ( Windows / Mac ):
1. Find path ( Ctrl + Shift + F / Ctrl + Shift + F ) :
This keyboard shortcut is very useful for every developer. Just imagine if you find to find any code or any line from whole project files. By navigating each file and check for required line might be tedious job. In this situation this android studio keyboard shortcuts will be very helpful.
As you can see in the image i want to search for MovieListHeaderAdapter
. Where that adapter used and all other information so in this case i have used Ctrl + Shift + F .
2. Search everything ( Press Shift twice / Press Shift twice ) :
This is a very useful navigational shortcut. It is very simple to use. We can use this android studio keyboard shortcuts when we want to find out Android assests, image resources, layouts, navigate to android gradle file and many more.
You can go anywhere using Double shift press shortcut. Just press shift two times and one popup will appear as you can see in the above image.
I want to find out drawable_divider_view.xml
. So i pressed shift key twice and search for the same.
3. Find class ( Ctrl + N / Command + O ) :
This shortcut is useful when you want to navigate to any particular class. Take a note that you can’t find out any drawables, layouts or assets files using this shortcut.
As you can see in the image i want to search RecyclerViewGridLayoutActivity
class so i have used Ctrl + N android studio keyboard shortcuts.
4. Collapse / expand code blocks ( ( Ctrl + minus /plus ) / ( Command + minus / plus ) ) :
Now just assume that you have a layout file which contains thousands of lines of code. And in that layout file there are lots of hierarchy views and you might want to avoid some part of the code from hierarchy than this shortcut will definitely for you.
As you can see in the first image code is collapsed in a single line and in second line you can see expanded version of code.
For using this android studio keyboard shortcut you need to just go to line of code which you want to collapse and press Ctrl + minus / Command + minus . Same procedure if you want to expand but using Ctrl + plus / Command + plus.
5. Delete entire line ( Shift + Delete / Shift + Delete ) :
If you want to delete entire line of code at that time using Backspace will be time consuming. Instead we can use Shift + Delete. For using this shortcut you need to just go to line which you want to remove and press Shift + Delete.
6. Move line ( Ctrl + Shift + ( Up / Down ) / Command + Shift + ( Up / Down ) ) :
All developers are champion in copy and paste job. But sometimes selecting one line and doing copy and paste job for moving one line to bottom of another line can increase time in development. Instead we can use Ctrl + Shift + (Up / Down) / Command + Shift + ( Up / Down ).
For using this shortcut you need to go on the line which you want to move than just press Ctrl + Shift + (Up / Down) / Command + Shift + ( Up / Down ).
7. Switch between tabs in editor ( Ctrl + Tab / Command +Tab ) :
This is one of my favorite shortcut when i have opened lots of classes in android studio and i want to switch between those classes than this shortcut always best friend of mine.
After pressing Ctrl + Tab / Command +Tab you will able to see one popup as shown in image and than pressing tab key you can navigate to different classes. It is simple to use but very effective.
8. Navigate between open editor tabs ( Alt + ( Right / Left ) Arrow / Control + ( Right / Left ) Arrow ) :
Using this shortcut you can navigate between all open tabs in android studio. Difference between switching shortcut and navigation shortcut is you can navigate between tabs like we are doing in google chrome you can’t directly jump to other tab like we can do it using Switching tab shortcut ( Which we have discussed in No. 6 ).
This tab is most useful for me when i have two tabs open and i want to do some coding stuff in both classes and want to navigate between classes faster.
9. Recently edited files pop-up ( Control + Shift + E / Command + Shift + E ) :
When we are working on so many files some times we want to check files which we have recently updated at that time this shortcut is very useful. As shown in image just press Control + Shift + E / Command + Shift + E. One popup will open from which you can select recently updated files.
10. Reformat code( Control + Shift + E / Command + Shift + E ) :
This is mostly used shortcut. No need to manually indent all the nested if blocks or the for loops. Android Studio takes care of all the formatting. Just Press CTRL+ALT+L on Windows or Command+Option+L on Mac. The android studio will reformat all the code for you.
And the good part is that it works for XML layouts as well. It takes care of ordering of the xml attributes and indenting nested layouts in your code so that you focus more on coding and less on figuring out what is nested under what.
11. Generate code ( Alt + Insert / Command + N ) :
Alt L Shortcut For Mac In Android Studio Windows 7
It can be time consuming to type out all the boilerplate code such as getters / setters in model classes, toString implementation, Parcelable Implementation and much more. Android Studio does all this for you. Press ALT+Insert on Windows or Command+N on Mac and android studio will list out all the options that are available such as override methods, implement interfaces, toString implementation etc…
You can see in image Code Generation android studio keyboard shortcut.
Alt L Shortcut For Mac In Android Studio 64-bit
Conclusion
So this are the most important and useful shortcut which every productive android developer using everyday. Try your
fingers on it and become productive android developer. Jetbrains constantly improving android studio keyboard shortcuts so take advantages of it.
Useful Links:
Alt L Shortcut For Mac In Android Studio 32-bit
If you want me to write for you than contact me on twitter on from linkedin.