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!

You may also like...