Java 在 Android Studio 中更改作者模板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21160288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change Author template in Android Studio
提问by Shudy
I want to change the automatic author that appears when I create a file in AndroidStudio.
我想更改在 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.
作者采用“a556520”,但我希望出现我的名字,而不是员工人数。那可能吗?设置里没找到啊
采纳答案by AZ13
You can overwrite the ${USER}
variable in the template file with the
您可以使用以下命令覆盖${USER}
模板文件中的变量
#set( $VARIABLE = "value")
function. Go to Settings-> Editor-> File and Code Templates-> Includes-> File Headerprepend the #set()
function call, for example:
功能。转到Settings-> Editor-> File and Code Templates-> Includes-> File Header在#set()
函数调用之前添加,例如:
#set( $USER = "Your name" )
/**
* Created by ${USER} on ${DATE}.
*/
回答by Blaz
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.
您可以通过转到首选项 -> 编辑器 -> 文件和代码模板来更改文件头的模板。然后${USER}
在包含选项卡下的文件标题中更改。然而,这是硬编码解决方案,最好更改${USER}
变量的实际值。
回答by Divers
Press Ctrl+Alt+Sthen go to File and Code Templates. Here you can set up what you want. E.g. replace ${USER}
to your name.
按Ctrl+ Alt+S然后转到文件和代码模板。在这里你可以设置你想要的。例如替换${USER}
为您的名字。
回答by Zain
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}
*/
回答by Sami Eltamawy
To edit your File Header template, do the following:
要编辑文件头模板,请执行以下操作:
1)Open Android Studio Preferences
dialog.
1) 打开 Android StudioPreferences
对话框。
2)In the search box, write "File and Code Templates".
2) 在搜索框中,写入“文件和代码模板”。
3)Select the left menu item "File and Code Templates".
3)选择左侧菜单项“文件和代码模板”。
4)From the middle tabular navigation section, select Includes
.
4) 从中间的表格导航部分,选择Includes
。
5)Select File Header
item that applies to the Java files.
5)选择File Header
适用于Java文件的项目。
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.
6) 您将找到一个编辑器部分,允许您根据所需模式对其进行编辑。使用下面的描述部分来了解可以使用的不同参数。
/**
* 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:
注意:对于name
属性,可以不使用属性,直接直接写。您也可以以相同的方式添加公司名称或项目名称,例如:
/**
* Created by Sami on ${DAY},${MONTH_NAME_FULL},${YEAR}
* ABCDFG company,
* Dubai, UAE.
*/
回答by HymansOnF1re
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)
实际上,更改用户名的正确方法是更改登录到 Windows 的当前用户的名称。(如果您使用的是 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.
Android Studio 使用保存在 %USERNAME% 变量中的名称。这是您whoami
在命令控制台或批处理文件中键入时获得的名称。它是存储在 C(orWhatEver):\User 下的名称。
To change the name you can notjust 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.
要更改名称,您不能只更改您登录的配置文件的名称。您需要创建一个新用户并为其指定正确的名称。这样,即使有一天你重新安装AndroidStudio,你也会${USER}
再次以正确的方式结束。
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.
更简单的方法当然是将您的名字硬编码到模板中。但这只是治标不治本,您应该使用方法解决根本原因。
回答by della pramukti raharjo
- 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}
**/
- 打开 Android Studio 首选项对话框。
- 在搜索框中,输入“文件和代码模板”。
- 选择左侧菜单项“文件和代码模板”。
- 从中间的表格导航部分,选择包括。
- 选择适用于 Java 文件的文件头项。
- 您将找到一个编辑器部分,允许您针对所需的模式对其进行编辑。使用下面的描述部分来了解可以使用的不同参数。
先设置属性。
#set ($USER = "Your name")
#set ($COMPANY = "Your company")
#set ($EMAIL = "Your email")
/**
Created by ${USER} on ${DAY},${MONTH_NAME_FULL},${YEAR} ${COMPANY} ${EMAIL}
**/