Android Studio template usage and custom templates

Source: Internet
Author: User

This article GIF graph is more, may cause the page to load slowly, please everybody waits patiently

Today we will learn some of the secrets of the Android Studio software, these are the template, that is, we output some specific characters can be automated to write a lot of code, the amount, what meaning? Let's look at the picture below to understand it!

Live Template

This template usage is to enter a specific character, press the TAB key, this key can be customized settings

Enter Toast in the method and press the TAB key

Quickly write the tag, enter "Logt" in the class and press the TAB key

The constants are written in detail in the figure


The correct posture for writing the output statement

The correct code method for the log print statement

How to sentence an empty/non-empty statement to an object

Intentview is called cool.

The demonstration first came here, then you may ask, how do you know the keywords to enter? Do I say I guess you believe it? Whether you believe it or not, I don't believe it anyway. -_-! so I'm going to show you how to find these input keywords.
Posture: Settings > Editor > Live Templates

You can go to see for yourself, see if you have what you need, learn and write it down, and then use the code to write the work, let us code writing faster and more hi!

It may be used to find that I might want to implement my own live Template, OK? The answer is yes.

Customizing the Live Template

Specific method or look at the picture, here to create a similar "Logt" effect, I hope you can be based on this implementation of a number of complex, here to achieve a simple "mytag"

File Template

When you create a class in as, I believe everyone has seen a comment on the class name.

/** * Created by 你的电脑用户名 on 当前的日期. */

This can also be modified, see figure:

Let's create some of our favorite file template A hungry man-type singleton class, the template code is as follows < This template as comes with;:
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end#parse("File Header.java")publicclass ${NAME}{    privatestaticnew ${NAME}();    publicstatic ${NAME} getInstance() {        return ourInstance;    }    private ${NAME}() {    }}

Do you worry about not automatically inheriting activity when creating activity for as?

Custom activity Class File template code is as follows:

#if"")package ${PACKAGE_NAME};#end#parse("File Header.java")publicclass ${NAME} extends AppCompatActivity {    @Override    protectedvoidonCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);    }}

Android Studio template usage and custom templates

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.