Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio live template not working

I've created a Live Template under the "user" template group. I've set the Abbreviation to "setpref". It is listed on my list of Live Templates, but it is not available when I type "setpref" in a code window. I'm guessing that I've missed something obvious but can't work out what. Any ideas??

like image 286
Ian M Avatar asked Feb 08 '15 15:02

Ian M


People also ask

How do I use live templates?

To create a Live Template, in Android Studio or IntelliJ open Preferences ‣ Editor ‣ Live Templates. In this window, you can explore some of the existing templates you can use, what their shortcuts are, and edit the shortcuts and generated code. This is also where you can create a new template.

What is live template in Android Studio?

Android Studio (and in consequence, IntelliJ) comes with a feature called Live Templates which allow developers to customize shortcuts or abbreviation that translates to written code. Following the previous example, we have a default shortcut for that, in Java and in Kotlin.

Can we use template in Android Studio?

Android Studio provides code templates that follow the Android design and development best practices to get you on the right track to creating beautiful, functional apps. You can use templates to create new app modules, individual activities, or other specific Android project components.


2 Answers

To make the Live Templates appear again, do the following:

1) Open Editor>Live Templates

2) When you find templates with issues, select them and do step 4-6

3) At the bottom, click Change where it says "Applicable in..."

4) In the popup, under Java select statement to make templates like logd, logm, logw etc be available inside methods.

5) Select declaration to make templates like logt available in classes' field declarations.

Done!

Visit this link - https://www.reddit.com/r/androiddev/comments/3n9nis/issues_with_live_templates_in_android_studio_try/?st=j0pjkc4w&sh=e84eb254

Have fun ! :) It works.

like image 185
Tom Avatar answered Oct 08 '22 11:10

Tom


Please make sure that you've correctly specified the context for your live template (the set of languages in which it's available).

like image 40
yole Avatar answered Oct 08 '22 13:10

yole