Alt L Shortcut In Android Studio

  1. Alt L Shortcut In Android Studio 8
  2. Alt L Shortcut In Android Studio Download
  3. Android Studio Ctrl Alt L
  • Android Studio (Windows/Linux) Keyboard Shortcuts from Kekc42. Android Studio (Windows/Linux) Keyboard Shortcuts from Kekc42. Auto-i­ndent 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.

ShortcutAndroid

Keyboard Shortcuts

Android Studio Open File Shortcut

DescriptionWindows/LinuxMac
General
Save allControl + SCommand + S
SynchronizeControl + Alt + YCommand + Option + Y
Maximize/minimize editorControl + Shift + F12Control + Command + F12
Add to favoritesAlt + Shift + FOption + Shift + F
Inspect current file with current profileAlt + Shift + IOption + Shift + I
Quick switch schemeControl + ` (backquote)Control + ` (backquote)
Open settings dialogueControl + Alt + SCommand + , (comma)
Open project structure dialogControl + Alt + Shift + SCommand + ; (semicolon)
Switch between tabs and tool windowControl + TabControl + Tab
Navigating and Searching Within Studio
Search everything (including code and menus)Press Shift twicePress Shift twice
FindControl + FCommand + F
Find nextF3Command + G
Find previousShift + F3Command + Shift + G
ReplaceControl + RCommand + R
Find actionControl + Shift + ACommand + Shift + A
Search by symbol nameControl + Alt + Shift + NCommand + Option + O
Find classControl + NCommand + O
Find file (instead of class)Control + Shift + NCommand + Shift + O
Find in pathControl + Shift + FCommand + Shift + F
Open file structure pop-upControl + F12Command + F12
Navigate between open editor tabsAlt + Right/Left ArrowControl + Right/Left Arrow
Jump to sourceF4 / Control + EnterF4 / Command + Down Arrow
Open current editor tab in new windowShift + F4Shift + F4
Recently opened files pop-upControl + ECommand + E
Recently edited files pop-upControl + Shift + ECommand + Shift + E
Go to last edit locationControl + Shift + BackspaceCommand + Shift + Backspace
Close active editor tabControl + F4Command + W
Return to editor window from a tool windowEscEsc
Hide active or last active tool windowShift + EscShift + Esc
Go to lineControl + GCommand + L
Open type hierarchyControl + HControl + H
Open method hierarchyControl + Shift + HCommand + Shift + H
Open call hierarchyControl + Alt + HControl + Option + H
Writing Code
Generate code (getters, setters, constructors, hashCode/equals, toString, new file, new class)Alt + InsertCommand + N
Override methodsControl + OControl + O
Implement methodsControl + IControl + I
Surround with (if…else / try…catch / etc.)Control + Alt + TCommand + Option + T
Delete line at caretControl + YCommand + Backspace
Collapse/expand current code blockControl + minus/plusCommand + minus/plus
Collapse/expand all code blocksControl + Shift + minus/plusCommand + Shift + minus/plus
Duplicate current line or selectionControl + DCommand + D
Basic code completionControl + SpaceControl + Space
Smart code completion (filters the list of methods and variables by expected type)Control + Shift + SpaceControl + Shift + Space
Complete statementControl + Shift + EnterCommand + Shift + Enter
Quick documentation lookupControl + QControl + J
Show parameters for selected methodControl + PCommand + P
Go to declaration (directly)Control + B or Control + ClickCommand + B or Command + Click
Go to implementationsControl + Alt + BCommand + Alt + B
Go to super-method/super-classControl + UCommand + U
Open quick definition lookupControl + Shift + ICommand + Y
Toggle project tool window visibilityAlt + 1Command + 1
Toggle bookmarkF11F3
Toggle bookmark with mnemonicControl + F11Option + F3
Comment/uncomment with line commentControl + /Command + /
Comment/uncomment with block commentControl + Shift + /Command + Shift + /
Select successively increasing code blocksControl + WOption + Up
Decrease current selection to previous stateControl + Shift + WOption + Down
Move to code block startControl + [Option + Command + [
Move to code block endControl + ]Option + Command + ]
Select to the code block startControl + Shift + [Option + Command + Shift + [
Select to the code block endControl + Shift + ]Option + Command + Shift + ]
Delete to end of wordControl + DeleteOption + Delete
Delete to start of wordControl + BackspaceOption + Backspace
Optimize importsControl + Alt + OControl + Option + O
Project quick fix (show intention actions and quick fixes)Alt + EnterOption + Enter
Reformat codeControl + Alt + LCommand + Option + L
Auto-indent linesControl + Alt + IControl + Option + I
Indent/unindent linesTab/Shift + TabTab/Shift + Tab
Smart line joinControl + Shift + JControl + Shift + J
Smart line splitControl + EnterCommand + Enter
Start new lineShift + EnterShift + Enter
Next/previous highlighted errorF2 / Shift + F2F2 / Shift + F2
Build and Run
BuildControl + F9Command + F9
Build and runShift + F10Control + R
Apply changes (with Instant Run)Control + F10Control + Command + R
Debugging
DebugShift + F9Control + D
Step overF8F8
Step intoF7F7
Smart step intoShift + F7Shift + F7
Step outShift + F8Shift + F8
Run to cursorAlt + F9Option + F9
Evaluate expressionAlt + F8Option + F8
Resume programF9Command + Option + R
Toggle breakpointControl + F8Command + F8
View breakpointsControl + Shift + F8Command + Shift + F8
Refactoring
CopyF5F5
MoveF6F6
Safe deleteAlt + DeleteCommand + Delete
RenameShift + F6Shift + F6
Change signatureControl + F6Command + F6
InlineControl + Alt + NCommand + Option + N
Extract methodControl + Alt + MCommand + Option + M
Extract variableControl + Alt + VCommand + Option + V
Extract fieldControl + Alt + FCommand + Option + F
Extract constantControl + Alt + CCommand + Option + C
Extract parameterControl + Alt + PCommand + Option + P
Version Control / Local History
Commit project to VCSControl + KCommand + K
Update project from VCSControl + TCommand + T
View recent changesAlt + Shift + COption + Shift + C
Open VCS popupAlt + ` (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 Alt L Shortcut In Android StudioDependency Inversion Principle — these are principles for object oriented design which was popularized by Robert C. Martin

Alt 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 Project

To 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

AbbreviationDescriptionCode
fbcFind view by ID with cast($cast$) findViewById(R.id.$resId$);
constDefine an Android style constantprivate static final int $name$ = $value$;
ToastCreate a new ToastToast.makeText($classname$.this, “$text$”).show();
foriCreates for loopfor(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

Android

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.

ShortcutWhat it does
Press Shift twiceIt 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 + SpaceAndroid 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 + NWe’ve used this in the previous section where we generated some code. This is the shortcut for the code generator
CTRL + O | Command + OWhen 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 + LDon’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