177

I want to change the automatic author that appears when I create a file in AndroidStudio.

/**
 * Created by a556520 on 16/01/14.
 */
public class POI {

The author takes 'a556520' but I want that appears my name, and not the number of employee. Is that possible? I didn't find in the settings.

8 Answers 8

432

You can overwrite the ${USER} variable in the template file with the

#set( $VARIABLE = "value")

function. Go to Settings -> Editor -> File and Code Templates -> Includes -> File Header prepend the #set() function call, for example:

#set( $USER = "Your name" )
/**
* Created by ${USER} on ${DATE}.
*/
4
  • 2
    Thanks to all, I will take this question as "accepted" just because I fell that is more.. "cleaner". But all are Ok. Thanks!
    – Shudy
    Commented Jan 16, 2014 at 15:26
  • 1
    Here you could find a full Doc on the topic
    – T04435
    Commented Aug 22, 2015 at 5:50
  • 8
    Is there any way I can apply it to the classes or files that I already created? Commented Dec 20, 2016 at 8:07
  • Is there a way to do this on a per project basis?
    – Axel
    Commented Jan 17, 2017 at 18:38
104

The above answers are correct. But you can go even further and define your own variables - such as User, Company, Email etc.:

#set ($USER = "Name name")
#set ($COMPANY = "company Ltd")
#set ($EMAIL = "[email protected]")

/**
 * Created by ${USER} on ${DATE}.
 * ${COMPANY}
 * ${EMAIL}
 */
0
76

To edit your File Header template, do the following:

1)Open Android Studio Preferences dialog.

2)In the search box, write "File and Code Templates".

3)Select the left menu item "File and Code Templates".

4)From the middle tabular navigation section, select Includes.

5)Select File Header item that applies to the Java files.

6)You will find an editor section that allow you to edit it for the required pattern. Use the description section below to understand the different parameters that can be used.

/**
* Created by ${USER} on ${DAY},${MONTH_NAME_FULL},${YEAR}
*/

enter image description here

Note: For the name attribute, you can simply write it directly without using attributes. Also you can add your company name or project name in the same way also such as:

/**
* Created by Sami on ${DAY},${MONTH_NAME_FULL},${YEAR}
* ABCDFG company,
* Dubai, UAE.
*/
0
22

Press Ctrl+Alt+S then go to File and Code Templates. Here you can set up what you want. E.g. replace ${USER} to your name.

9

Actually the correct way to change the username is to change the name of the current user logged in into Windows. (if you're using windows)

Android Studio uses the name saved in %USERNAME% variable. This is the name you get if you type whoami into a command console or batch file. And it is the name that is stored under C(orWhatEver):\User.

To change the name you can not just change the name of the profile you are logged in. You need to create a new user and give it the correct name. This way, even if you reinstall AndroidStudio some day, you will end with the correct ${USER} again.

The easier way surely is to just hard code your name into the template. But that is just treating the symptoms and you should use the way to fix the root cause.

1
  • 2
    Perfect answer, but, not always you can create or change the %USERNAME&, in my case, when I asked it, It was, because I got a Work computer, where my "username" was my loggin id in the company (aXXXXX), and can't create new user ^^. But as you said, if you have the change to change USERNAME or create new account, will be better. Thanks!
    – Shudy
    Commented Sep 21, 2015 at 10:01
9

Settings -> Editor -> File and Code Templates -> Includes -> File Header

/**
 * @Author: yourname
 * @Date: ${DATE}
 */

enter image description here

7

You can change template for file header by going to Preferences -> Editor -> File and Code Templates. Then change ${USER} in File Header under Includes tab. However this is hardcoding solution it would be better to change actual value of ${USER} variable.

3
  • Open Android Studio Preferences dialog.
  • In the search box, write "File and Code Templates".
  • Select the left menu item "File and Code Templates".
  • From the middle tabular navigation section, select Includes.
  • Select File Header item that applies to the Java files.
  • You will find an editor section that allow you to edit it for the required pattern. Use the description section below to understand the different parameters that can be used.
  • Set the properties first. #set ($USER = "Your name") #set ($COMPANY = "Your company") #set ($EMAIL = "Your email")

    /**Created by ${USER} on ${DAY},${MONTH_NAME_FULL},${YEAR} ${COMPANY} ${EMAIL} **/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.