In the process of writing code using Androidstudio, with the increase in usage time and the use of various plug-ins, we found a lot of quick and fast way to hit the code. Such as:
"somethind".log
Can print out the contents of log logs directly
Log.d("MainActivity""something");
There are many such shortcuts, such as the use of the. If, the use of the Toast+tab key, the use of the fori directly to complement the For loop structure, these shortcuts are androidstudio available to developers, some features are provided by plugins, For details, you can find the as-used plugin.
Get rid of some shortcuts provided by plugins
Androidstudio also gives us a lot of quick-wake-up-knocking code, in the Androidstudio template
In the template of this mode, a number of shortcut key wake-up functions are specified, such as const is defined as a static int type, and FBC directly plays the Findviewbyid form with cast transformation, such as gone, Set the Visibility property value of the view to View.gone, which is not introduced here, in addition to the Androidstudio to provide us with these shortcut templates, we can also customize the template that conforms to their own habits.
First look at the template usage provided by Androidstudio
In the layout file, you can also use the
I have customized some of the use of fast wake-up function, you can watch the effect.
The above simple demonstration of the use of several templates can be based on the habits and needs of developers to customize some of the shortcut keys to use, such as the above demonstration, VC to create a parameterless construction method, the PRI quickly complement the definition of the INT type variable.
The correct use of the template, can greatly speed up the speed of tapping the code and save development time.
Here's how to set up a custom template by using graphics and text.
First open the Androidstudio Settings panel, one option is to select preferences by Androidstudio options, or to open them in Androidstudio by cmd+ commas
Select Editor-live Templates in the Settings panel, in the popup panel, you can find that there are many androidstudio prescribed shortcuts, the default way of using the tab shortcut key, shortcut template settings can be used in Android, Can be used in XML layout files.
Then by the right of the + button, create a new group, the name of the custom, on behalf of our custom shortcut key display template combination name.
The name is custom-defined by the developer.
Then select the created combination and create a custom template with the + button in the group group
Then define a name for the template, note that this name needs to be noted because it represents a shortcut that is used later in the code, that is, the shortcut key that wakes up the template. Similar to the PRI,VC shown in the above GIF image.
I named here is docu, and then fill in the text below the template style, that is, the shortcut key popup code template, you can also add a description in description. The content code of the dollar symbol package can be filled in by method calculation, because here we demonstrate the parameterless constructor method, so the class name is computed to get the class name of the class in which the code is located.
Then set the location of the template to display, select the location shown by the Define key below
There are a lot of options here, and what we've chosen here is the Java code used in the
After we set up the classname, we need to choose its method, in order to get the class name of the class, by the way of edit variables in the popup window set.
This allows us to complete a custom template setting through the template functionality provided by Androidstudio, which is the use of the parameterless construction method, or the other templates can be set up in this way, and the content of the code will be displayed differently, if needed in an XML layout file. Then the display location will be selected XML.
After the setup is complete, the template can be awakened by a custom name docu in the code, and then click OK to fill in the template content, where the class name section is calculated from the classname () method. There are many ways to do this, such as date dates, time, and so on.
So that we can speed up the code through the use of the template, in the late I try to create the adapter template, where the class name and the optimized cache class and the required member variables can be obtained by calculation, the effect is very good. is the necessary choice to go out of the show code, a key to knock out the adapter, then only need to configure some specific parameters. Finally, I wish to see this blog friend knocking code without bugs.
Use of code templates in Androidstudio