Make coding faster on Android Studio with Templates — Part 1 (Live Templates)
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.
- 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:
- Part 2: https://medium.com/@ikhwan220397/make-coding-faster-on-android-studio-with-templates-part-2-file-and-code-templates-c5c4da8f8e78
- Part 3: https://medium.com/@ikhwan220397/make-coding-faster-on-android-studio-with-templates-part-3-activity-templates-3fc44b2245b5
Thank you :D