“This is the third day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021.”
AndroidStudio dynamic templates
What are dynamic templates and what do templates look like in the AndroidStudio tools? When you Create an Activity or Java class, a prompt like “Create by xx on date” appears at the top. This is the default template that comes with AndroidStudio.
There are a lot of templates in AndroidStudio, you can edit templates in advance, then use shortcut keys, with automatic prompts, quickly and easily generate template files. This is a dynamic template. In order to develop quickly, it is important for developers to master dynamic templates.
Creating a Dynamic Template
Operating environment: Android Version system: MaxOs
AndroidStudio -> Preference -> Editor -> Live Templates
As you can see, there are many templates for both Android and Java. So let’s create a simple file class annotation template.
Class comment template
- Select the Android group and click the plus sign in the upper right corner to add it
- Fill in the information: abbreviation (quick to type using keyboard shortcuts), description (for yourself)
- Focus code Template text
- Select scope, which means which part of the code format this template code works in.
The template I used is in this format. $DATE$is a variable that represents the DATE the file was created. Note can be used to describe the remarks of the current class.
/**
* @author by xx, Date on $DATE$.
* note:
*/
Copy the code
Use note in the shortcut keys to quickly call.
Code split template
Sometimes there is too much code and you want to use a separator to separate it, so you can create the following template
// --------------------------------------------
//
// $value$ Start
//
// --------------------------------------------
Copy the code
The Buddha bless
Sometimes we put a big Buddha at the beginning of the class to protect the code from bugs. Did this Buddha copy itself? We use dynamic templates for a quick fix, creating a template first.
// // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`---'\___ // .' \\| |// '. // / \\||| : | | | / / / / / / _ | | | | | - : - | | | | | - \ / / | | \ \ \ / / / | | / / | \ _ | \ ' '-' | _ / |. / / \ \ __ '-' ___ / -. / / / ___ '... ' / -- -- \ `.. '___ / /. ""' < `. ___ \ _ < | > _ / ___." "' > '. / / | | : ` - \ `.; ` \ _ / `; . ` / - ` : | | / / \ \ ` _ / _ __ / / __ _ /. - ` / / / / = = = = = ` - ____ `. ___ \ _____ / ___ - ` ___. - '= = = = = / / ` = - =' / / / / / / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ / / / / the Buddha bless never BUGCopy the code
Then quickly use your input shortcut key English letters can be used, is not very cool ~ of course, the system also provides us with a lot of practical templates, then see
Built-in System Template
Constant TAG
Quickly type the constant TAG, using the shortcut key const
private static final int $name$ = $value$;
Copy the code
Binding view
FindViewById basic action to quickly bind views, using the shortcut FBC
($cast$) findViewById(R.id.$resId$);
Copy the code
Rapid foreach
Quick foreach method problem, using the shortcut key foreach
for ($i$ : $data$) {
$cursor$
}
Copy the code