Android Studio: how to remove/update the “Created

2019-01-20 22:16发布

By default Android Studio automatically adds a header comment to all new classes, e.g.

/**
 * Created by Dan on 11/20/13.
 */

Where is the setting to customize or remove it?

8条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-20 22:42

You can overwrite the ${USER} variable in the template file with the #set( $VARIABLE = "value") function.

On windows: Press Ctrl+Alt+S and go to Settings -> File and Code Templates -> Includes -> File Header

On Mac: Android Studio -> Preferences -> Editor -> 
File and Code Templates -> Includes -> File Header

prepend the #set() function call, for example:

#set( $USER = "YourName" )
/**
* Created by ${USER} on ${DATE}.
*/
查看更多
贪生不怕死
3楼-- · 2019-01-20 22:43

From the menu bar:

  • on Mac OS choose Android Studio -> Preferences
  • on Windows and Linux choose File -> Settings

Then look for Editor -> File and Code Templates in the left hand pane.

You have two ways you can change this...

1) Select the Includes tab and edit the Created by... text directly.

enter image description here

2) Select the Templates tab and edit the #parse("File Header.java") line for any template that you desire.

templates tab edit

Personally I followed option 1) and made the default header comment a TODO, e.g.

/**
 * TODO: Add a class header comment!
 */

These instructions are based on Android Studio v0.3.7. and also tested on v1.2.1.1

查看更多
够拽才男人
4楼-- · 2019-01-20 22:44

As well as Dan's answer (which is the much more rigorous way), you can also click into the header, and option-enter (on Mac), and you can choose to edit the default file template. Alternatively, click the little lightbulb to get here as well

enter image description here

查看更多
SAY GOODBYE
5楼-- · 2019-01-20 22:49

In case you want to remove all comments which have already been created. Hit Ctrl + Shift + R to open the Replace in path dialog. Check the Regex option and replace

/\*\*\n \* Created by .*\n \*/

with nothing.


The regex was originally posted by nerdinand as comment to the following answer. Although I asked him, he didn't create an answer for several months. That is why I did now, so people can find this more easily.

查看更多
趁早两清
6楼-- · 2019-01-20 22:51

You can just disable the warning as well. For me the default template was ok but seeing yellow highlighted class javadoc was annoying me. So to disable it go to Settings -> Editor -> Inspections -> General -> Uncheck "Default File Template Usage".

You can also do it accross all projects. Just change the Project profile to Default in the same Inspections tab.

查看更多
再贱就再见
7楼-- · 2019-01-20 22:56

Settings->Editor->Copyright->Copyright Profiles

is another place (apart from "Settings->Editor->File and Code Templates") where similar template could be defined and also triggered whenever file is created.

查看更多
登录 后发表回答