Android Studio Live Templates

I was really wondering how I can remove repetitive tasks from Android Studio by assigning shortcuts or tags and I found that IntelliJ has Live Templates which I bet that little programmers use. So as an example I wanted when I type the word “tag” within a class the following to be autocompleted:

public static final String TAG = MyClass.class.getSimpleName();

and I didn’t want to write anything by myself. Just by writing “tag” and pressing TAB this should be written.
To do it:

  1. Open File -> Settings -> Live Templates
  2. In the “other” category press the + to the right and select Live Template to add new element
  3. In abbreviation add “tag” and in template text add: “public static final String TAG = $CLASS_NAME$.class.getSimpleName();$END$”
  4. In the applicable context select Java – Declarations
  5. Click Edit Variables and select the className() method in the Expression column. And check the skip if defined value.
  6. Now when you write “tag” and press tab everything should be populated!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s