Custom Android Studio method annotation template, androidstudio
Preface
When you switch from Eclipse to Android Studio, will you miss the Eclipse method annotation template?
When you press/** and press enter, the template is displayed, but Android Studio cannot be customized (or I cannot find it)
Now I have found an alternative, that is, using live templates.
Procedure
1. File-> Setting-> Editor-> Live Templates
2. Click + to create a Template Group.
2. Enter the group name you want. My name is custom.
3. Select the group you just created and create a Live Template
4. Fill in Abbreviation. Here I fill in the cmt, that is, the shortcut for your comment. When you press cmt and press enter, the template will come out.
Template text is a annotated Template. You can write any Template as needed. My Template is as follows:
5. To set where your cmt shortcut will take effect, my choice is to take effect at the time of declaration, that is, you can press cmt and press enter on the method name.
6. I noticed that my Template text defines three variables: desc, date, and time. The next two variables are generated by date and time. Therefore, we need to edit these two variables.
Click Edit variables. In the displayed window, set the corresponding method for date and time. The date () method generates the date and time () method generates the time.
7. Click Apply. Now, you only need to press cmt on the method name and press enter to automatically generate the annotation template. The effect is as follows, and the time is automatically generated.