10 Android Studio Tips you may not know

Source: Internet
Author: User

Excessive reliance on the mouse when writing code can lead to more serious problems than inefficiency. Here's the trick to help you write less code and get the most out of your keyboard, so you can avoid situations like this:

Thanks Obama.

Most of the tricks here are IntelliJ features, and Android Studio is based on IntelliJ. The most memorable shortcut for Android Studio is cmd-shift-a (if you're a Windows or Linux PC, it's ctrl-shift-a).


Use Cmd-shift-a or ctrl-shift-a to find actions or options

After you press this shortcut, you just enter the keywords, and then the available actions and options are listed. This is a great way to start learning to use new features before you're familiar with the shortcuts for these actions or options.

You can also use a similar approach when you encounter a long list of options. For example, if you find a file in the project structure, or want to choose an option from a multilevel menu, such as refactor this, just type in the relevant words, and studio will help you find and filter the results.


Use tab to replace existing methods and variables when auto-complete

Pressing TAB replaces existing methods and values rather than just inserting a new one.

The Ctrl-space (or ctrl-shift-space for options of the expected type) that brings up the auto-completion feature may be the most commonly used shortcut key in Android Studio.

But everyone has to go through it. When you choose a new method or a new variable, if you press ENTER, the new selection is inserted before the existing code, and you must delete the previous code.

However, if you use tab instead of enter at this point, the existing method or variable will be replaced directly. Save a lot of trouble.

Text Selection Tips

The top and bottom keys, and the combination of CTRL, SHIFT, and Fn cover most of the cursor movement requirements-but the Alt modifier adds some new features you don't expect.

You can use the alt-up and Alt-down implementations to expand and narrow your selection by "nodes"-making it more efficient to choose your code.

At the same time, alt-shift-up and Alt-shift-down allow you to move up or down the current row, eliminating the hassle of copying and pasting the order of adjustments.

Code complement suffix Word with live Templates

In the spirit of writing less code to earn more money, it is recommended that you use a good code complement suffix and Live template to insert the most common code templates.

Use the code completion suffix to replace the typed expression with a code template.

For example, you can use the. fori suffix on a list to create a for loop, or use. if (or. else) on a Boolean variable to create an if statement. You can use Cmd-j (or ctrl-j-windows/linux) to see all the suffixes that a context has.

For more complex templates, Live Templates lets you use shortcut keys to complete auto-completion, which inserts a template code snippet. For example, you can easily add a toast-display code by using the shortcut key for toast. The shortcut for a Toast is tab, and when you press TAB after the toast, you can generate a line of code that shows the toast, just fill in the exact text.

/span>

There are many common or Android-specific live Templates, including log-you can also create your own live Template.


Customize object Rendering when evaluating an expression (that is, the value of a variable at debug time).

When you debug the code at run time, the value of the object displays the value of its. toString (). If your variable is a string or a basic data type, there is no problem, but the vast majority of objects show a little useful information.

This is especially true for collection objects, which are usually displayed as "Classname:hashvalue" in the form of a list.

However, you can create a custom renderer for any type of object.

Simply right-click on the Debugger page, select "View as" →create, then define your own calculation expression. Note that the variable or method in an expression must be the object itself.

Structural Search, Replace, and inspection

Structured search and replace allows you to search and replace code with templates without the use of regular expressions. You can use the cmd-shift-a mentioned above to bring up the search box, enter search or structural to find the operation.

Structural Replace Inspections Let's Create Your Own Lint Checks with quickfixes

More useful is that you can enable the inspection of structured searches. A structured search is saved, and then when you edit the code, the code that matches the search template is flagged to display the text you provide.

Therefore, it can be used to mark code that does not conform to the pattern.

What's more, it's about creating a structured replacement template of your own. As with the structured search template, the matching code will have a warning flag-but this time it will provide you with the code to be replaced for quick modification.

It is a perfect way to modify outdated code or code that does not conform to the specification, or the code submitted by other team members, when the code is reviewed.

There are hundreds of tips on how to make Android Studio experience faster, more efficient, and less mouse-free. Subscribe to the Android developers on YouTube and find the Android tool time to see more Android Tool Time advanced tips.

10 Android Studio Tips you may not know

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.