Showing posts with label android studio. Show all posts

How To Create Live Templates In Android Studio


In this article, we will see how to create Live Templates in Android Studio or IntelliJ IDE products like WebStorm, PHPStorm, etc. Live Templates are very useful to increase the speed of development, efficiency, and accuracy.
Predefined Live Templates
Android Studio has some predefined live templates such as “psfi” which is a simplification of “private state final int”. The following are some additional predefined templates.
How to create your own Live Templates
We can create our own live templates using the following method.
  1. Open Android Studio and select File >> Settings as shown in Figure 1.

    Android
    Figure 1
  1. Now, the Settings popup is shown. Select Editor >> Live Templates. It lists the Live Templates categorized by their type or Languages as shown in Figure 2.

    Android
    Figure 2
  1. Then, select or click plus +.Select TemplateGroup and give a name for your Template Group as shown in Figure 3.

    Android
    Figure 3
  1. Select your Template Group and click plus +. Select Live Template and name your template, add your code and define your language like XML by selecting clicking Define like in Figure 4.

    Android
    Figure 4
  1. To use it, type the template abbreviation we have created and hit enter which replaces the code written in your template.
  2. Typing the abbreviation shows the template saved as shown in Figure 5 and hit Enter.

    Android
    Figure 5
  1. Which replaces the code typed by you.

    Android
We can do the same for all languages. This will increase the development speed, efficiency, and accuracy of code construction. If you like this article, do like and share and post your doubts in the comments section.