10 Android Studio Tips you might not know about

Source: Internet
Author: User

English Original: Medium

      • When you can't remember how a feature is used
      • Modify shortcut keys
      • What you need to know about auto-completion
      • Replace the current method or value with the Tab key after auto prompt
      • When you've finished writing a line of code
      • Three Tips for positioning
      • Automatically generated code templates based on suffixes
      • Tips for customizing object display at Debug time
      • Summarize

Android StudioIs every Android development tool to use every day, but even if you are an experienced developer, you may have missed a lot of life-saving techniques, and this article may help you master some of them. I will not translate word, but in the most concise and understandable way to introduce to you, while providing the necessary annotations and extensions, so that you can quickly read after a quick grasp.

When you can't remember how a feature is used

If you are a windows/linux user, then please press, Ctrl + Shift + A if you are a MAC user, then press Command + Shift + A , in this universal input box you can enter the action you want to perform (of course, in English), the list will show the corresponding optional action and shortcut keys. Not only the operation, if you just want to change a setting, you can also use this function, for example, if you want to set gradle for offline work, you can enter the input box offline, the corresponding result of the toggle offline For example, if you need to open the Auto Import function when pasting code, then just type in the input box Auto Import and select the corresponding item.

Modify shortcut keys

All shortcut keys are customizable in Android Studio. Please call the great Ctrl + Shift + A , input keymap, choose the Settings > Keymap option is located, here can see all the fast key, generally not recommended in the original shortcut key program directly modify the shortcut, but copy an existing plan to change the above, In the Keymaps drop-down box to select an existing scheme (default is the defaults), click on the right of copy, and then in the list need to modify the shortcut keys on the item right-click, select Add Keyboard Shortcut , and then you can set your favorite shortcut keys, if you set the shortcut keys and other keys conflict, Will be prompted with a red error message.

Because of the number of shortcut keys in the list, we can also use the search box on the right to search, such as the need to modify the basic auto-completion of the shortcut keys we just enter Basic , we can find the corresponding item in the results.

What you need to know about auto-completion

In general, when using Android Studio, Automatic prompts will automatically appear when you want to prompt, such as log. Log.d(), Log.e, Log.i() But if you choose the wrong hand when you are automatically prompted, such as to choose LOG.D () results selected LOG.E (), you will not have. E () are deleted, and then enter a. In fact, this need to re-call the automatic completion of the situation only need to use Ctrl + Alt + 空格 it.

In fact, there are two ways: first, the basic complement Ctrl + 空格 , but the Windows user is not happy, because this and windwos system switch Input Method shortcut key conflict, if you do not want to modify this shortcut, then use Ctrl + Alt + 空格 as an alternative, if you want to modify this fast key, Then you can use the method of the previous section to set new shortcut keys, search for basic in the Keymaps interface, and then choose to set in the filtered results, and the Code->Completion->Basic other is the intelligent completion Ctrl + Shift + 空格 , but the smart complement is far more than this function, when you call the method, You can use smart completion to associate variables that conform to the method parameter type in the current context.

Replace the current method or value with the Tab key after auto prompt

If we manually call out the auto-completion, the current position has a corresponding method or variable (such as originally called Obj's a method, and then we position the cursor to the position of the A method, call out the auto-completion, I hope the automatic completion of the B method instead of a method), this time if we select the completion of the project, press ENTER, Then the completion of the content will be inserted in front of the original content, this is not what we want, in fact, should not press ENTER, but tab.

When you've finished writing a line of code

This is very common, when you finish writing a line of code, the cursor is not at the end of the current line, the more common is the right side of the cursor and N a right parenthesis, what will you do? You may use the arrow keys to move the cursor to the end of the line, and then manually enter one; In fact, there is a simpler solution, that is Ctrl + Shift + 回车 , this shortcut will help you automatically fill in the missing parts of the current expression, including input at the end of the line, it is worth mentioning that the shortcut is also valid for the If,else,for,while control loop.

Another situation where the cursor is not at the end of the line, but you want to be able to insert a blank row in the next line, Shift + ENTER can help you accomplish this task.

Three Tips for positioning

Using 4 arrow keys to position the cursor is the most familiar method, but it can be more convenient. While holding down CTRL while pressing the arrow keys, you can move one word at a time by holding down ALT while pressing the UP and down keys, you can move a node (method or field) one node, or you Shift + Ctrl can swap positions between the current row and the upper and lower lines if you press and hold the up and down keys.

Automatically generated code templates based on suffixes

In the process of daily use of the editor, there are a lot of fixed formatting, such as If-else, for, and so on, using code templates to help us generate the desired code faster. For example, first enter a variable of the collection type and add the suffix. fori, the automatic prompt prompts you to generate a for loop for that collection type, in the same way that an expression of Boolean type plus an. If suffix can also produce an if statement that is conditional on the expression.

In fact, the above two code templates are IntelliJ, and Android Studio also provides many Android-related code templates, such as the creation of toast and parcelable templates, and the way to view all available templates and custom templates is first Ctrl + Shift + Acall out the universal search box, enter Live templates and select Live Templates in Settings, where you can see all the available code templates.

Tips for customizing object display at Debug time

When debugging code, we often need to look at the value of an object. Especially the custom object, we often do not implement its ToString method, then this object in the IDE's value is Classname:hashvalue this way. We need to open this object to see the values of each member within it. There is a better way to do this without implementing the ToString method. In the Debug Variable window, right-click the object you want to view, and select View as both to set how the object will appear in the debug state.

Summarize

Thank you for seeing this.

10 Android Studio tips you might not know about

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.