Thanks to: Yissan of CSDN Thanks to: Kaku of Jane Book I’m just a porter. The url of their article is attached at the end of the article.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — I were porters code — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
An overview of the
Nowadays development is increasingly pursuing efficiency and rhythm, saving time to do more things, in addition to the development of technical packaging, development tools use skills are also very important, today based on their own experience to introduce you to the Rapid development of Android Studio.
Postfix completion
Postfix Completion is a long-established feature of IntelliJ IDEA that allows you to implement another expression you want based on the expression you’ve entered and the suffix you’ve added. For example, adding the suffix if after a Boolean expression is an if statement. Introduction to common suffixes
Here are some suffixes that I find more common in my work.
- cast
When a variable needs to be cast, how often do you go back multiple times to the name of the variable and type it in parentheses? Now you just need.cast to type it in.
- If You have a better option for the if statement,.if
- Elseelse is if inverse, that’s how fast it is
- Let’s say your code is long, and suddenly at 1000 lines you have to assign a value to a variable and declare it as a global variable. You don’t want to go back and redeclare it. With Field, you can be anywhere.
- Fori simple fast for loop, just like that
- Forfor loop type 2, enhanced for loop (same effect with.iter)
- Forrfor loop type 3, reverse for loop. Forr
- Null Fast nulls
- Nn /notnull quickly determines that it is notnull. Nn, which is the same as
- Switch. Switch generates switch statements directly from objects of type such as string enumeration
- Inst/instantsOF Fast instanOF judgment and type conversion
- Var quickly generates variables for an expression
- Par quickly adds parentheses to an expression
- Log Indicates the fast log. Log
- Quick toast, the content you want to output
In addition to the above suffixes, Android Studio has a number of other suffixes that I don’t think are very commonly used, so I won’t mention them. You can open setting-editor-general-Postfix Completion to see more of them. Below is a picture of Postfix Completion
Live Templates
Lets you insert frequently used or custom code structures to quickly, efficiently, and accurately build into your source code files. You can check Live Templates directly under the Editor by opening the Settings/Preferences dialog
Live Templates
As you can see from the image above, Android Studio already provides a number of templates. Here’s a quick look at Live Templates with one of the Templates provided by the system.
Let’s start with a picture
Add your own code template
In the figure above, Android is the name of a group under which the system provides many templates. We can click + in the upper right corner to add our own group or the Abbreviation of the template. After defining the Abbreviation, we can directly enter the Abbreviation to get the specific content of the template. Description is prompted by an accompanying Description. Tempplate text is the specific content, which can be defined by variable. The template in the figure above defines two variables, name and value.
You can Edit variables through the Edit Variables button on the right. Click it and the following dialog box will pop up
As you can see, name specifies the default value name. Value is a random number up to 1000. There are a lot of details about editing variables that I won’t go into here for space reasons, but I’ll write a blog post that covers the various features of Live Templelates in detail. Continuing with the first template, there is a change button in the lower left corner that you can click to specify the scope of the template. That’s the basic introduction. Look at the effect
There are a lot of Templates available and most of them are useful, so I’m not going to go through them all, but you can look at Live Templates and find out what works for you. You might not get used to it at first, but as you go, you get faster and faster. Once I learned about Live Templates, I found that I often wrote onClick when I was using ButterKnife, but it was the same code every time, so I was able to customize a template, as shown below:
Customizes a group called custom, and defines a template abbreviated onclick under this group. The template is a butterknife annotated click method and declares variable ids. Click Edit Variables as shown below
Specifies Expression to completeSmart(), indicating that the variable will be called intelligently (the cursor will appear at the variable position)
The specific effects are as follows:
The resource ID of the activity is assigned arbitrarily for convenience.
- If I’m writing code and I’ve been writing for half an hour, I realize that I’m writing a piece of code that I’ve written several times and will probably write again. Should we copy it and then go to Setting and go to Live Templates and add it? You could have done better! Select your code, go to “Tools” ->Save as Live Templates “and Save it by specifying abbreviations and other parameters. Or go to KeyMap, enter live Template, and go to Save as Live Templates. CMD + Shift +s = CMD +shift+s
Ps: because I have set before shortcuts, thought have default shortcut, want to have a look at the default shortcut keys to write it down, so point under the reset, found that this function does not provide a default shortcuts, then came the most tragic, found that I don’t have a point after reset the apply nima actually takes effect, all the shortcuts I modified all didn’t pull.
- Tip 2: What do you do when you want to use a template, but forget its abbreviation? Quick CMD + J, Windows, I don’t know, you’ll see insert Live Templates when you set up tip 1, and you’ll see the shortcuts. This feature prompts all the templates that are appropriate for the current scenario.
Of course there is a lot to know about Live Templates, such as the number of expressions used to define variables and what they stand for, but that is not the focus of this article, so I won’t go into it.
shortcuts
The keyboard shortcuts provided by Android Studio are very powerful, and I feel that as long as you are familiar with them, you can throw the mouse away from the moment you open Android Studio… Individuals often use shortcuts is introduced first to a wave of commonly used function shortcut effect demo, I didn’t figure is not subject to the ah (due to many here only do some demo), ps: the shortcuts here is based on the as own shortcuts type, if you choose the other shortcuts type (like eclipse), you only need to open the Settings, keymap, Enter the filter criteria to find the corresponding function to view the shortcut keys. The following format is Description/Windows or Linux shortcut keys/Mac shortcut keys
The picture
- Find Action (F3/Command + G)
- Find next (F3/Command + G
-
Find Previous Finds the previous one
-
Find class (Control + N/Command + O) opens class files directly through the class name filter, with this basic I rarely use the mouse to Find class files.
-
Duplicate current line or Selection (Control + D/Command + D) quickly generates a copy of a single or selected row
-
Go to Implementations (Control + Alt + B/Command + Alt + B) finds the implementation class of the current interface, or the implementation method of the interface method, which is most commonly used in MVP mode
-
Extract method(Control + Alt + M/Command + Option + M) Extract method(Control + Alt + M/Command + Option + M) Extract method(Control + Alt + M/Command + Option + M) Extract method(Control + Alt + M/Command + Option + M) Extract Method (Control + Alt + M/Command + M)
-
Extract variable(Control + Alt + V/Command + Option + V) generates temporary variables for selected expressions and prompts for unified replacement if multiple places are present.
-
Extract Field (Control + Alt + F/Command + Option + F) generates global variables for selected expressions and prompts for unified replacement if there are more than one place.
-
Next highlighted error(F2 / F2) you must look for an error in a very long code file, which is very troublesome, with this function, the cursor moves directly to the wrong place.
There is not enough space for this, other system shortcuts I have arranged in the form of a table, many functions you need to try to find its power.
Default system shortcut keys
Ps: This list is the system’s default shortcut keys. If you select Eclipse or other shortcut keys, you need to find the corresponding description to view or modify.
description | explain | Windows/Linux | Mac |
---|---|---|---|
Open settings dialogue | Quick open Settings | Control + Alt + S | Command + , (comma) |
Open project structure dialog | Open the project structure | Control + Alt + Shift + S | Command + ; (semicolon) |
Switch between tabs and tool window | TAB of the switch | Control + Alt + Shift + S | Command + ; (semicolon) |
description | explain | Windows/Linux | Mac |
---|---|---|---|
Find | To find the | Control + Alt + S | Command + , (comma) |
Search everything (including code and menus) | Find all | Click Shift twice to search | Click Shift twice to search |
Find next | Sequential search down | F3 | Command + G |
Find action | Search function, super powerful, as all functions can be searched through the function | Control + Shift + A | Command + Shift + A |
Find class | Quickly find the class and open the file | Control + N | Command + O |
Find file (instead of class) | Find files quickly | Control + Shift + N | Command + Shift + O |
Find in path | All path lookups under the project | Control + Shift + F | Command + Shift + F |
Recently opened files pop-up | List the most recently opened files | F3Control + E | Command + E |
Recently edited files pop-up | List the most recently edited files | Control + Shift + E | Command + Shift + E |
Go to last edit location | Return to the position of the last edit | Control + Shift + Backspace | Command + Shift + Backspace |
Close active editor tab | Close the currently edited file | Control + F4 | Command + W |
Open type hierarchy | Turn on type hierarchies | Control + H | Control + H |
Open method hierarchy | Open method hierarchy | Control + Shift + H | Command + Shift + H |
Open call hierarchy | Open the call hierarchy | Control + Alt + H | Control + Option + H |
description | explain | Windows/Linux | Mac |
---|---|---|---|
Generate code (getters, setters, constructors, hashCode/equals, toString, new file, new class) | Generate various methods quickly | Alt + Insert | Command + N |
Override methods | Shows all methods that can be overridden | Control + O | Control + O |
Implement methods | Shows all the methods that can be implemented | Control + I | Control + I |
Surround with (if… The else/try… catch / etc.) | Quickly generate if else, try catch for loops for statements, etc | Control + Alt + T | Command + Option + T |
Delete line at caret | Deletes the line where the cursor is located | Control + Y | Command + Backspace |
Duplicate current line or selection | Quickly generate a new current line, or a new multi-line code | Control + D | Command + D |
Quick documentation lookup | Quick review of brief documents | Control + P | Command + P |
Go to declaration (directly) | Find the variable or method declaration | Control + B or Control + Click | Command + B or Command + Click |
Go to implementations | Find the implementation class of an interface. The interface method is the implementation | Control + Alt + B | Command + Alt + B |
Go to super-method/super-class | Find the parent class or parent method | Control + U | Command + U |
Toggle project tool window visibility | Shows or hides the project window to the left of as | Alt + 1 | Command + 1 |
Comment/uncomment with line comment | Quick single line comment or uncomment | Control + / | Command + / |
Comment/uncomment with block comment | Multi-line gaze or removal of multi-line comments | Command + Shift + / | Command + Shift + / |
Project quick fix (show intention actions and quick fixes) | Give multiple solutions to the current problem (this method is very common) | Alt + Enter | Option + Enter |
Reformat code | Formatting code | Control + Alt + L | Command + Option + L |
Next/previous highlighted error | Find the next/last mistake | F2 / Shift + F2 | F2 / Shift + F2 |
description | explain | Windows/Linux | Mac |
---|---|---|---|
Build | compile | Control + F9 | Command + F9 |
Build and run | compile | Shift + F10 | Control + R |
description | explain | Windows/Linux | Mac |
---|---|---|---|
Debug | Shift + F9 | Shift + F9 | |
Step over | F8 | F8 | |
Step into | F7 | F7 | |
Smart step into | Shift + F7 | Shift + F7 | |
Resume program | F9 | Command + Option + R |
description | explain | Windows/Linux | Mac |
---|---|---|---|
Safe delete | Safely delete | Alt + Delete | Command + Delete |
Extract method | Extraction method | Control + Alt + M | Command + Option + M |
Extract method | Extraction method | Control + Alt + V | Command + Option + V |
Extract variable | Extract variable | Control + Alt + V | Command + Option + V |
Extract field | Extracting global variables | Control + Alt + F | Command + Option + F |
Extract constant | Extract constant | Control + Alt + C | Command + Option + C |
Extract parameter | To extract the parameters | Control + Alt + P | Command + Option + P |
description | explain | Windows/Linux | Mac |
---|---|---|---|
Commit project to VCS | Control + K | Command + K | |
Update project from VCS | Control + T | Command + T | |
View recent changes | View Recent Changes | Alt + Shift + C | Option + Shift + C |
Open VCS popup | The version control Settings window is displayed | Alt + ` (backquote) | Control + V |
extension
- We can achieve powerful functions with a few simple keys, but sometimes the shortcuts provided by many systems may conflict with those of your own system, or some powerful functions as does not provide you with shortcut keys. This is where customization (modification or addition) of shortcut keys is involved. For example, the finding and highlighting error code as mentioned above provides an F2 key, but on the Mac it is a function key and I want to keep it, so I changed it to Command + Shift +2
I will not mention the shortcut key customization, we baidu there are a lot of articles.
- KeyMap lists many functions, space and energy is limited, can not be listed one by one, you have time to open Settings -> keyMap, to see the shortcut keys inside, not sure of their own press to try, you will find that the original can be so convenient.
Android Studio plugin
2.ButterKnife Annotation generator: ButterKnife Zelezny 3.Selector file generation: SelectorChapek 4. GsonFormat 5.Parcelable automation: Android Parcelable Code Generator 6. Generate ViewHolder and findView methods: AndroidCodeGenerator 7. Code line statistics: statistic 8. Code retrieval: Codota 9. Simulator: Genymotion 10. Quick Log, Toast, isEmpty code writing: postfix 11.Android Studio translation plugin, you can translate English into Chinese: ECTranslation: Github.com/Skykai521/E… Lifecycle method positions can be sorted by the Lifecycle of an Activity or fragment: Lifecycle Sorter 14. FindBugs helps you find hidden bugs and bad practices: Findbugs-idea 15. The site has a huge collection of code, boasting over 700W code examples: Codota 16. PermissionsDispatcher is a plugin that can quickly generate Runtime Permissions code in an Activity/Fragment for API 23. Android Material Design Icon Generator 19.Material Theme Material Theme UI 20.Android efficient development and debugging wizard: JRebel:zeroturnaround.com/ 21. Claims on the Android platform second level compiled program: Freeline:yq.aliyun.com/articles/59…
To Install the plug-in, go to File -> Settings -> Plugins -> Browse Repositories, type in the plug-in name search, and click “Install”. If you can’t find it, you can download it here and select “Install Plugin from Disk “to Install it offline.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — handling the end — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Continue to collect the best Android Studio add-ons ~~ select the right ones!