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