简体   繁体   中英

How to edit template in Android Studio / JetBrains IntelliJ IDEA?

I wonder to add changed "loge" template in the Android Studio editor to remove the last required param - Exception object. How "loge" template result looks now:

Before the dafualt template insert:

public void doSmth() {
    //start write "loge" word here
}

After the dafualt template insert:

public void doSmth() {
    Log.e(TAG, "doSmth: ", );
}

So to add template you have to follow several simple steps:

  1. Open "Settings -> Editor -> Live templates -> AndroidLog" 设置->编辑器->实时模板-> AndroidLog
  2. Click the plus button, select "1. Live Template"
  3. Fill the fields like I did:
    • Abbreviation: le
    • Description: Log.e(TAG, String)
    • Template text: android.util.Log.e(TAG, "$METHOD_NAME$ failed: $content$"); 填写字段
  4. Click "Edit varables", select "methodName()" for METHOD_NAME variable 编辑变量对话框
  5. One more important thing! Define context to Java -> Statement: 定义Java上下文->语句
  6. Click "Apply", click "OK", Enjoy your own template! :)

Official documentation is here .


Your template in work: 您的模板在工作中 在此处输入图片说明

public void doSmth() {
    Log.e(TAG, "doSmth failed: ");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM