Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Author template in Android Studio

People also ask

How to edit template in Android Studio?

Just by pressing ⏎ (Enter) or ⇥ (Tab) Android Studio will insert the selected template in the editor, and it will put the cursor at the first $EXPR$ variable from the template (in this case the function name). Once we are done typing the name, we can press ⏎ or ⇥ again to jump to the next $EXPR$ variable.


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}.
*/

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}
 */

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.
*/

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.


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.


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.


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

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

enter image description here