- Alt L Shortcut In Android Studio 8
- Alt L Shortcut In Android Studio Download
- Android Studio Ctrl Alt L
- Android Studio (Windows/Linux) Keyboard Shortcuts from Kekc42. Android Studio (Windows/Linux) Keyboard Shortcuts from Kekc42. Auto-indent lines.
- The Android Studio keymap settings window. Keymaps dropdown: Select the desired keymap from this menu to switch between preset keymaps. Actions list: Right click on an action to modify it. You can add additional keyboard shortcuts for the action, add mouse shortcuts to associate an action with a mouse click, or remove current shortcuts.
- All of these shortcuts work for Android Studio and IntelliJ in Windows. Are you coming from iOS? Just press Ctrl+Alt+L to fix your indentation and reformat code.
- 34 Shortcuts for Android Studio. General Shortcuts. Ctrl + Shift + N. Alt + Arrow Left / Arrow Right. Navigate open tabs.
Android Studio comes with pre-defined keyboard shortcuts for many common actions. Specified below is the table showcasing the default android studio keyboard shortcuts as per your operating system.
Keyboard Shortcuts
Android Studio Open File Shortcut
Description | Windows/Linux | Mac |
---|---|---|
General | ||
Save all | Control + S | Command + S |
Synchronize | Control + Alt + Y | Command + Option + Y |
Maximize/minimize editor | Control + Shift + F12 | Control + Command + F12 |
Add to favorites | Alt + Shift + F | Option + Shift + F |
Inspect current file with current profile | Alt + Shift + I | Option + Shift + I |
Quick switch scheme | Control + ` (backquote) | Control + ` (backquote) |
Open settings dialogue | Control + Alt + S | Command + , (comma) |
Open project structure dialog | Control + Alt + Shift + S | Command + ; (semicolon) |
Switch between tabs and tool window | Control + Tab | Control + Tab |
Navigating and Searching Within Studio | ||
Search everything (including code and menus) | Press Shift twice | Press Shift twice |
Find | Control + F | Command + F |
Find next | F3 | Command + G |
Find previous | Shift + F3 | Command + Shift + G |
Replace | Control + R | Command + R |
Find action | Control + Shift + A | Command + Shift + A |
Search by symbol name | Control + Alt + Shift + N | Command + Option + O |
Find class | Control + N | Command + O |
Find file (instead of class) | Control + Shift + N | Command + Shift + O |
Find in path | Control + Shift + F | Command + Shift + F |
Open file structure pop-up | Control + F12 | Command + F12 |
Navigate between open editor tabs | Alt + Right/Left Arrow | Control + Right/Left Arrow |
Jump to source | F4 / Control + Enter | F4 / Command + Down Arrow |
Open current editor tab in new window | Shift + F4 | Shift + F4 |
Recently opened files pop-up | Control + E | Command + E |
Recently edited files pop-up | Control + Shift + E | Command + Shift + E |
Go to last edit location | Control + Shift + Backspace | Command + Shift + Backspace |
Close active editor tab | Control + F4 | Command + W |
Return to editor window from a tool window | Esc | Esc |
Hide active or last active tool window | Shift + Esc | Shift + Esc |
Go to line | Control + G | Command + L |
Open type hierarchy | Control + H | Control + H |
Open method hierarchy | Control + Shift + H | Command + Shift + H |
Open call hierarchy | Control + Alt + H | Control + Option + H |
Writing Code | ||
Generate code (getters, setters, constructors, hashCode/equals, toString, new file, new class) | Alt + Insert | Command + N |
Override methods | Control + O | Control + O |
Implement methods | Control + I | Control + I |
Surround with (if…else / try…catch / etc.) | Control + Alt + T | Command + Option + T |
Delete line at caret | Control + Y | Command + Backspace |
Collapse/expand current code block | Control + minus/plus | Command + minus/plus |
Collapse/expand all code blocks | Control + Shift + minus/plus | Command + Shift + minus/plus |
Duplicate current line or selection | Control + D | Command + D |
Basic code completion | Control + Space | Control + Space |
Smart code completion (filters the list of methods and variables by expected type) | Control + Shift + Space | Control + Shift + Space |
Complete statement | Control + Shift + Enter | Command + Shift + Enter |
Quick documentation lookup | Control + Q | Control + J |
Show parameters for selected method | Control + P | Command + P |
Go to declaration (directly) | Control + B or Control + Click | Command + B or Command + Click |
Go to implementations | Control + Alt + B | Command + Alt + B |
Go to super-method/super-class | Control + U | Command + U |
Open quick definition lookup | Control + Shift + I | Command + Y |
Toggle project tool window visibility | Alt + 1 | Command + 1 |
Toggle bookmark | F11 | F3 |
Toggle bookmark with mnemonic | Control + F11 | Option + F3 |
Comment/uncomment with line comment | Control + / | Command + / |
Comment/uncomment with block comment | Control + Shift + / | Command + Shift + / |
Select successively increasing code blocks | Control + W | Option + Up |
Decrease current selection to previous state | Control + Shift + W | Option + Down |
Move to code block start | Control + [ | Option + Command + [ |
Move to code block end | Control + ] | Option + Command + ] |
Select to the code block start | Control + Shift + [ | Option + Command + Shift + [ |
Select to the code block end | Control + Shift + ] | Option + Command + Shift + ] |
Delete to end of word | Control + Delete | Option + Delete |
Delete to start of word | Control + Backspace | Option + Backspace |
Optimize imports | Control + Alt + O | Control + Option + O |
Project quick fix (show intention actions and quick fixes) | Alt + Enter | Option + Enter |
Reformat code | Control + Alt + L | Command + Option + L |
Auto-indent lines | Control + Alt + I | Control + Option + I |
Indent/unindent lines | Tab/Shift + Tab | Tab/Shift + Tab |
Smart line join | Control + Shift + J | Control + Shift + J |
Smart line split | Control + Enter | Command + Enter |
Start new line | Shift + Enter | Shift + Enter |
Next/previous highlighted error | F2 / Shift + F2 | F2 / Shift + F2 |
Build and Run | ||
Build | Control + F9 | Command + F9 |
Build and run | Shift + F10 | Control + R |
Apply changes (with Instant Run) | Control + F10 | Control + Command + R |
Debugging | ||
Debug | Shift + F9 | Control + D |
Step over | F8 | F8 |
Step into | F7 | F7 |
Smart step into | Shift + F7 | Shift + F7 |
Step out | Shift + F8 | Shift + F8 |
Run to cursor | Alt + F9 | Option + F9 |
Evaluate expression | Alt + F8 | Option + F8 |
Resume program | F9 | Command + Option + R |
Toggle breakpoint | Control + F8 | Command + F8 |
View breakpoints | Control + Shift + F8 | Command + Shift + F8 |
Refactoring | ||
Copy | F5 | F5 |
Move | F6 | F6 |
Safe delete | Alt + Delete | Command + Delete |
Rename | Shift + F6 | Shift + F6 |
Change signature | Control + F6 | Command + F6 |
Inline | Control + Alt + N | Command + Option + N |
Extract method | Control + Alt + M | Command + Option + M |
Extract variable | Control + Alt + V | Command + Option + V |
Extract field | Control + Alt + F | Command + Option + F |
Extract constant | Control + Alt + C | Command + Option + C |
Extract parameter | Control + Alt + P | Command + Option + P |
Version Control / Local History | ||
Commit project to VCS | Control + K | Command + K |
Update project from VCS | Control + T | Command + T |
View recent changes | Alt + Shift + C | Option + Shift + C |
Open VCS popup | Alt + ` (backquote) | Control + V |
Now Select the portion of the text you want to format and press ctrl + Alt + L; Reformat Code in Android Studio « Learn Android The Easy Way, Android Studio and IntelliJ also provides a check box named Format code on save on the Flutter page in Preferences (on Mac) or Settings (on Windows and Linux) Format the code is really important for.
Android Studio Debug Shortcuts
Favourite Keyboard Shortcuts. We also received suggestions for Android Studio from Maher Nabeel: In Android Studio: Ctrl + D — Duplicate line; Ctrl + Y — Delete line. A good selection of Sublime Text 3 shortcuts for Windows, Mac, and Linux can be found here. Remember these Shortcuts Navigation Go to class O Go to file O Go to symbol O Go to next / previous editor tab / Go back to previous tool window F12 Go to editor (from tool window) Hide active or last active window Go to line L. DEFAULT KEYMAP. Created Date. Android Studio Shortcuts. Android Studio is the android apps making software for Windows and use emulator for preview & download pdf here Shortcut Key Keyboard shortcuts.
What we usually mean when talking about productivity is that we want to do what we need to do in the shortest possible time; that means keyboard shortcuts, templates, snippets etc. In this section, we’ll take a peek at some of what Android Studio has to offer give our productivity a little boost. We won’t go into detail; that’s not the goal, but rather just to show you what’s available in Android Studio.
Contents
Import Samples
One way to boost your productivity and save time is to learn how to create things and discover how they work in Android Studio. The Import Sample feature can save you a lot of time. You can get to this feature from the main menu bar of Android Studio, choose File > New > Import Sample.
What you see in figure 1 above is a list of code samples you can either browse or create as a local project.
Let’s say I’d like to learn something about the Autofill Framework — like what you see you in figure 1, you can see a preview of what it looks like, and you can also click on the “Browse in GitHub” link. When you click Next, you’ll see dialog that’s somewhat similar to when creating a new project, as shown in figure 2.
If you click “Finish” on “Import Sample” dialog, Android Studio will create a new project locally and download the sample file from GitHub so you can take a closer look at it and work on right away.
Refactoring
Refactoring is basically rewriting and improving your source code without creating new functionality; this practice helps keep the code SOLID, DRY (don’t repeat yourself) and hence, easier to maintain.
NOTE. I spelled SOLID in all caps because it’s also an acronym which stands for Single Responsibility, Open Closed Principle, Liskov Principle, Interface Segregation and Dependency Inversion Principle — these are principles for object oriented design which was popularized by Robert C. MartinAlt L Shortcut In Android Studio 8
Android Studio has some nifty refactoring capabilities. It’s easy to get started, just select a piece of code that you’d like to refactor, then use the context sensitive right-click, as shown in figure 3. Alternatively, you can also use the keyboard shortcuts — CTRL + T for macOS and CTRL + Alt + Shift + T if you’re on Windows/Linux.
I’m sure you’ve done refactoring many times before, but let’s just jog our memories here.
- Rename. This will let you safely rename variables and other identifiers etc. You should use this instead of Find and Replace. This works across the entire project, and not only in the current file
- Change Signature. This will let you change a method, either its name or the parameters. It also works at a class level e.g. you can turn a class into a generic type and manipulate the type parameters
- Move. Move an element; you can move a method to another class if you want to
- Copy. Let’s you copy elements e.g. currently selected class
- Safe Delete. If you need to delete something, Android Studio will verify that what you’re deleting isn’t in use by anything else in the code base. If it is in use, you’ll be prompted so you can address those things before you actually delete something important
- Extract Constant. Avoid using hard-coded values — you shouldn’t, you know it and you know why. The Extract option for refactoring works not only for constants, you can extract fields, methods, superclasses, variable, parameter and interfaces
There are plenty more options in the Refactor menu; make sure to check the others out.
Generate
Another time-saving feature of Android Studio is the code generator; it’s aptly named because it does exactly what you think it does — it generates code. Let’s take an example; figure 4 shows the keyboard cursor inside a class definition, while the cursor is within the class body, launch the Generator action; from the main menu bar, go to Code > Generate.
As you can see, you can generate quite a lot of boiler-plate code. When you choose any of the Generate options, Android Studio will generate a generalized stub of code. Let’s choose the getter and setter option, shall we? Let’s say I have a PersonTest class, as shown in figure 8-5, while the keyboard cursor is still within the PersonTest class, go to the main menu bar, then Code > Generate — alternatively, you can use the keyboard shortcut Command + N (macOS) or Alt + Insert (Windows and Linux); then choose to generate Getter and Setter. You’ll see the generate setters and getters dialog, as shown in figure 5.
The generator dialog shows all the autodetected fields in our class. It shows us the mFirstname and mLastname member variables; it also lets you do multiple selection. Select both member variables and click OK. Listing 1 shows the PersonTest class after code generation.
Listing 1. PersonTest class
This is pretty neat already. Anything that lets us save on keystrokes is a good thing. I’m guessing you probably have just one thing to nitpick on this example; the method naming isn’t right. You probably would prefer to call** setLastname()** rather than setmLastname() don’t you? We’ll fix that in the next section.
Coding Styles
If you go to Android Studio’s Preferences or Settings, then go to Editor > Code Style > Java, you’ll find that there’s plenty of things you can change about how the editor behaves. Figure 8-7 shows the options for the Code Style, specifically the Java language.
If you want to change the number of spaces for tabs and indents, you can do that in the Tabs and Indents area; be sure to check out the other options in this dialog. What I’d like to do, is to go to the Code Generation tab (shown in figure 7).
This is where we can tell Android Studio how we name our variables. If you go back to listing 1, you’ll notice that I’d like to prefix my variables with m, like mLastname and mFirstname; initially, Android Studio didn’t know about it, that’s why when I generated some getters and setters for the member vars, it gave us setmLastname() instead of just setLastname().
NOTE. Prefixing a member variable with m comes from AOSP (Android Open Source Project). I used it here because quite a lot of sample codes you will read online uses this convention. You can further read about it at Android Open Source ProjectTo tell Android Studio that I prefix my variables with m, I’ll put the m in Name Prefix for Field; as shown in figure 6. Click OK when you’re done.
Now, if I generate some getters and setters, we’ll get the more appropriate method names. Listing 2 shows the re-generated code for PersonTest class.
Alt L Shortcut In Android Studio Download
Listing 2. PersonTest, regenerated
Live Templates
Another time-saver in Android Studio are Live Templates, it works a lot like those text expander applications, if you have used some of them. The basic idea is when you type a series of characters e.g. datetoday, then the editor will replace it with the text of the actual date today — that’s how live templates work.
If you’ve done some Android programming in the past, you’ve probably made this mistake at least once;
This is easy enough to spot, but some other errors may not be as obvious. Anyway, live templates can help you avoid these hassles. Live templates are shortcuts that are displayed as code-completion options; for example, try typing fbc inside an OnClick handler (or any event handler), as shown in figure 8.
You’ll see the code completion options. Try to press the TAB key and see what happens.
Android Studio Ctrl Alt L
Here are some common built-in templates; as listed in table 1.
Table 1. Common Live Templates
Abbreviation | Description | Code |
---|---|---|
fbc | Find view by ID with cast | ($cast$) findViewById(R.id.$resId$); |
const | Define an Android style constant | private static final int $name$ = $value$; |
Toast | Create a new Toast | Toast.makeText($classname$.this, “$text$”).show(); |
fori | Creates for loop | for(int $INDEX$ = 0;$INDEX$<$LIMIT$;$INDEX++$ ) { $END$ } |
Make sure you check out the other Live Templates, go to the Settings or Preferences window. If you’re on Windows or Linux, go to the main menu bar, then File > Settings > Editor > Live Templates; if you’re on macOS, it’s at Android Studio > Preferences > Editor > Live Templates — you can even create your own Live Templates from there.
Important Keyboard Shortcuts
The Android developer website maintains a page where you can find the keyboard shortcuts for Android Studio, it’s at http://bit.ly/androidstudiokbshortcuts. You should really make it a point to read that page; but before we close the chapter, I’d like to leave you with 6 shortcuts that I find to be very useful for me — it could be useful for you too. Table 2 lists these shortcuts.
Shortcut | What it does |
---|---|
Press Shift twice | It lets you search for a term everywhere. It searches assets folder, gradle files, images resources, codes, xml configuration files etc. If you don’t know which folder to search, just use this |
CTRL + Space | Command + Space | Android Studio already has code completions and code hinting; this is just a little extra. If you forgot the parameters for a method that uses lots of parameters, you can use this to preview all the variants of method and the corresponding parameters they expect |
ALT + Insert | Command + N | We’ve used this in the previous section where we generated some code. This is the shortcut for the code generator |
CTRL + O | Command + O | When you want to override methods, use this shortcut |
CTRL + - | Command + - | You can use these to expand or collapse code blocks. It’s handy to be able to fold codes when you’re working with a large codebase, these shortcuts will make your life a bit easier when you fold/unfold blocks |
CTRL + Alt + L | Command + Option + L | Don’t manually indent or re-indent your code — if you messed up the indentation of a for loop or nested conditional blocks, just highlight the code block and use this shortcut |
Android Studio Quick Reference
There are more tips like this in the book
Get the book