Change Author template in Android Studio

前端 未结 7 1092
盖世英雄少女心
盖世英雄少女心 2020-12-22 17:43

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 {


        
相关标签:
7条回答
  • 2020-12-22 17:57

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

    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 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-22 18:06

    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}.
    */
    
    0 讨论(0)
  • 2020-12-22 18:09
    • 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} **/

    0 讨论(0)
  • 2020-12-22 18:12

    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.

    0 讨论(0)
  • 2020-12-22 18:17

    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 = "example@gmail.com")
    
    /**
     * Created by ${USER} on ${DATE}.
     * ${COMPANY}
     * ${EMAIL}
     */
    
    0 讨论(0)
提交回复
热议问题