Android Studio productivity tips. Learn how about automatic code generation, live templates, how to import sample codes and the important keyboard shortcuts you can start using today to boost your productivity. Or go with the non-mouse option: Double tap ALT and on the second tap hold ALT down and use the arrow keys to select the lines you want. With the following shortcuts you can extract selected code blocks to either a function, variable, property, parameter or functional parameter: ALT + CMD + M method/function. ALT + CMD + V variable.

Example

It's possible to have your own custom code styles, share them with other team members and use a shortcut to auto format the code in a file.

To create your own custom code style, go to: Preferences -> Editor -> Code Style

There are some general code style settings here. You can also select the language (Java for Android) and set the parameters as you see fit. There's a lot of settings.

Once you've done this, save your code style. This is just for safe keeping.

Once you've saved it, select 'Copy to Project' from the 'Manage' dialog. You will be asked whether you want to switch to this created scheme. Answer yes.

Once this is done, close the Code Style preferences dialog.

Now, verify that your code style settings have been saved in: .idea/codeStyleSettings.xml

Ensure that this file is not ignored in your version control system so that you can share it with your teammates.

Once your teammates have this file, they should also have the same settings.

Now, when editing a file, you can format the code by selecting:

Code -> Reformat Code

Shortcuts for Reformat Code (taken from this answer - see answer for details on resolving issues with shortcut in Ubuntu):

Win

Ctrl + Alt + L

Linux:

Ctrl + Shift + Alt + L

Alt L Shortcut In Android Studio 8

Mac:

Option + Command + L

When you perform a code reformat, a small dialog should popup informing you of the changes made. You can click 'Show' in this dialog to bring up the 'Reformat File Dialog'.

You can also bring up this dialog from the Code menu and its corresponding shortcut.

Be warned that 'Only VCS changed text' doesn't always work depending on how the code has been edited (it may ignore a rule if part of the code has not been edited).

You can also select text and show the reformat code dialog to format only the select text.



If you're unfamiliar with using Android Studio and the IntelliJ IDEA interface, this page provides some tips to help you get started with some of the most common tasks and productivity enhancements.

Productivity Shortcuts

Android Studio includes a number of features to help you be more productive in your coding. This section notes a few of the key features to help you work quickly and efficiently.

Smart Rendering

With smart rendering, Android Studio displays links for quick fixes to rendering errors. For example, if you add a button to the layout without specifying the width and height attributes, Android Studio displays the rendering message Automatically add all missing attributes. Clicking the message adds the missing attributes to the layout.

Bitmap rendering in the debugger

While debugging, you can now right-click on bitmap variables in your app and invoke View Bitmap. This fetches the associated data from the debugged process and renders the bitmap in the debugger.
Figure 1. Bitmap Rendering

Creating new files

You can quickly add new code and resource files by clicking the appropriate directory in the Project pane and pressing ALT + INSERT on Windows and Linux or COMMAND + N on Mac. Based on the type of directory selected, Android Studio offers to create the appropriate file type.
For example, if you select a layout directory, press ALT + INSERT on Windows, and select Layout resource file, a dialog opens so you can name the file (you can exclude the .xml suffix) and choose a root view element. The editor then switches to the layout design editor so you can begin designing your layout.

Output window message filtering

When checking build results, you can filter messages by message type to quickly locate messages of interest.
Figure 2. Filter Build Messages

Hierarchical parent setting

The activity parent can now be set in the Activity Wizard when creating a new activity. Setting a hierarchal parent sets theUp button to automatically appear in the app's Action bar when viewing a child activity, so the Up button no longer needs to be manually specified in the menu.xml file.

Creating layouts

Android Studio offers an advanced layout editor that allows you to drag-and-drop widgets into your layout and preview your layout while editing the XML.
While editing in the Text view, you can preview the layout on devices by opening the Preview pane available on the right side of the window. Within the Preview pane, you can modify the preview by changing various options at the top of the pane, including the preview device, layout theme, platform version and more. To preview the layout on multiple devices simultaneously, select Preview All Screen Sizes from the device drop-down.
Figure 3. Preview All Screens
You can switch to the graphical editor by clicking Design at the bottom of the window. While editing in the Design view, you can show and hide the widgets available to drag-and-drop by clicking Palette on the left side of the window. ClickingDesigner on the right side of the window reveals a panel with a layout hierarchy and a list of properties for each view in the layout.

Annotations

Android Studio provides coding assistance for using annotations from the Support-Annotations library, part of the Support Repository. Adding a dependency for this library enables you to decorate your code with annotations to help catch bugs, such as null pointer exceptions and resource type conflicts. You can also create enumerated annotations to, for example, check that a passed parameter value matches a value from a defined set of constants. For more information, seeImproving Code Inspection with Annotations.

Java class decompiling

Android Studio allows you to look at what’s inside Java libraries when you don’t have access to the source code.
The decompiler is built into Android Studio for easy access. To use this feature, right-click a class, method, or field from a library for which you do not have source file access and select decompile.
To adjust the Java decompiler settings, select File > Settings > Other Settings > Java Decompiler.

Debugging and performance enhancements

Android Studio offers debugging and performance enhancements such as:
  • Custom keymaps. To modify the current keymap, choose File > Settings > Keymap.
  • Support for high density (Retina) displays on Windows and Linux.
  • Scratch files for quick prototyping without creating any project files.
    Choose Tools > New Scratch File to open a scratch file to quickly build and run code prototypes. Together with Android Studio coding assistance, scratch files allow you to quickly run and debug code updates with the support of all file operations. By embedding code created with scripting languages, you can run your code from within the scratch file.

Live templates

Live templates allow you to enter code snippets for fast insertion and completion of small chunks of code. To insert a live template, type the template abbreviations and press the Tab key. Android Studio inserts the code snippet associated with the template into your code.
For example, entering the newInstance abbreviation followed by the Tab key inserts the code for a new fragment instance with argument placeholders.
Similarly, the fbc abbreviation inserts a findViewById call along with cast and resource id syntax.

Alt L Shortcut In Android Studio Free

Use the File > Settings > Editor > Live Templates menu option to display the full list of supported live templates and customize the inserted code.

Working with IntelliJ-based Coding Practices

This section list just a few of the code editing practices you should consider using when creating Android Studio apps.

Alt + Enter key binding

Alt l shortcut in android studio download
For quick fixes to coding errors, the IntelliJ powered IDE implements the Alt + Enter key binding to fix errors (missing imports, variable assignments, missing references, etc) when possible, and if not, suggest the most probable solution.

Ctrl + D key binding

The Ctrl + D key binding is great for quickly duplicating code lines or fragments. Simply select the desired line or fragment and enter this key binding.

Navigate menu

In case you're not familiar with an API class, file or symbol, the Navigate menu lets you jump directly to the class of a method or field name without having to search through individual classes.

Inspection scopes

Scopes set the color of code segments for easy code identification and location. For example, you can set a scope to identify all code related to a specific action bar.
Alt L Shortcut In Android Studio

Injecting languages

Alt L Shortcut In Android Studio Windows 10

With language injection, the Android Studio IDE allows you to work with islands of different languages embedded in the source code. This extends the syntax, error highlighting and coding assistance to the embedded language. This can be especially useful for checking regular expression values inline and validating XML.

Code folding

This allows you to selectively hide and display sections of the code for readability. For example, resource expressions or code for a nested class can be folded or hidden in to one line to make the outer class structure easier to read. The inner class can be later expanded for updates.

Image and color preview

When referencing images and icons in your code, a preview of the image or icon appears (in actual size at different densities) in the code margin to help you verify the image or icon reference. Pressing F1 with the preview image or icon selected displays resource asset details, such as the dp settings.
Alt L Shortcut In Android Studio

Quick F1 documentation

You can now inspect theme attributes using View > Quick Documentation (F1), see the theme inheritance hierarchy, and resolve values for the various attributes.
If you invoke View > Quick Documentation (usually bound to F1) on the theme attribute ?android:textAppearanceLarge, you will see the theme inheritance hierarchy and resolved values for the various attributes that are pulled in.

Keyboard Commands

Alt L Shortcut In Android Studio Download

The following tables list keyboard shortcuts for common operations.
Note: This section lists Android Studio keyboard shortcuts for the default keymap. To change the default keymap on Windows and Linux, go to File > Settings > Keymap. If you're using Mac OS X, update your keymap to use the Mac OS X 10.5+ version keymaps under Android Studio > Preferences > Keymap.
ActionAndroid Studio Key Command
Command look-up (autocomplete command name)CTRL + SHIFT + A
Project quick fixALT + ENTER
Reformat codeCTRL + ALT + L (Win)
OPTION + CMD + L (Mac)
Show docs for selected APICTRL + Q (Win)
F1 (Mac)
Show parameters for selected methodCTRL + P
Generate methodALT + Insert (Win)
CMD + N (Mac)
Jump to sourceF4 (Win)
CMD + down-arrow (Mac)
Delete lineCTRL + Y (Win)
CMD + Backspace (Mac)
Search by symbol nameCTRL + ALT + SHIFT + N (Win)
OPTION + CMD + O (Mac)
>. Project and editor key commands
ActionAndroid Studio Key Command
BuildCTRL + F9 (Win)
CMD + F9 (Mac)
Build and runSHIFT + F10 (Win)
CTRL + R (Mac)
Toggle project visibilityALT + 1 (Win)
CMD + 1 (Mac)
Navigate open tabsALT + left-arrow; ALT + right-arrow (Win)
CTRL + left-arrow; CTRL + right-arrow (Mac)