Make coding faster on Android Studio with Templates — Part 1 (Live Templates)

Ikhwan Koto
3 min readApr 28, 2020

--

Hello everyone, in this post we will discuss Templates on Android Studio. There are 3 parts of this topic because every topic has a different goal.

If you want to read this post in Bahasa, you can open this link: https://www.yukngoding.id/2020/04/16/buat-ngoding-lebih-cepat-di-android-studio-dengan-templates-part-1-live-templates/

In this part, we will discuss Live Templates. We have a goal like shown below:

How to do it? Let’s begin.

  1. Click File > Settings in the menu (or Android Studio > Preferences for MacOS)

2. Click Live Templates

3. Create (or Select) a Template Group

After clicking the Live Template, set a name for the template.

4. Create a Live Template

After clicking Live Template, a form will be shown like below:

  • Abbreviation: a shortcut will be used later when to call the template
  • Description: description :D
  • Template text: template code will be shown when we select the template

5. Select the Live Template’s type

Before apply, we must select a type for our Live Template. Click Define and select our template’s type.

Because I created a template for the layout, so I define this template as XML. After that, click Apply and OK. The result will be as seen at the beginning of this post.

“ You can do it with the longest code, like using more than one TextView. ”

#EXTRA

We can add some expressions on Live Templates. One of them is Complete. The result of using it is like shown below:

How?

1. When we create a Live Template add a code that begins and ends with “$”. Example:

stringVal and spVal is a value can receive an expression.

2. Click Edit variables at the bottom of the description’s form. A window will be shown like below:

In Expression column for stringVal select complete()

3. Click OK and OK again

Done, with this, we can use Live templates like an example.

We are at the end of this post and thank you for spending your time reading this post.

Visit this link for another part:

Thank you :D

--

--