自定义AndroidStudio中的默认Header信息

When you create a new class file in Android Studio, it will automatically add a header to it. By default the header contains the user/author name and file created date. Something like ‘Created by user on date‘.

Android-Studio-File-Header-Text

This header can be customized to change the name of the author and also to include other information.

Here’s how,

Bring up the Settings dialog, (File > Settings). Search for ‘File and Code Templates‘  or alternatively navigate toEditor > File and Code Templates. Click on the ‘Includes‘ tab and then select ‘File Header‘ from the left pane. The content of the ‘File Header‘ template will be displayed on the right pane.

Android-Studio-File-and-Code-Templates-Settings

Notice how the default template contains two variables ${USER} and ${DATE}. While creating a new file Android Studio assigns the values to these variables and adds the output text in the file header.

The description pane below contains details of other available predefined variables that you can use in the template, for example, ${PACKAGE_NAME} will insert name of the package or ${PROJECT_NAME} will insert the name of the project etc. You can include any of these variables in the template and Android Studio will use them while generating the file header. What’s more, you can define your own variables or assign a new value to a predefined variable like $USER. For example, let’s change the user (author) name to ‘John Smith’ ,

#set ($USER = "John Smith")

Let’s also define a few new variables,

#set ($ORGANIZATION_NAME = "Super Awesome Company")
#set ($CONTACT_EMAIL= "example@domain.com")
#set ($PROJECT_URL= "http://urltomyawesomeproject.com")

Once the variables are defined and assigned values, you will need to include them in the template to actually use them. Here’s the completed template for reference,

android-studio-file-header-template

Now, lets create a new class file to test our new file header template. Here’s our custom file header in all its glory.

android-studio-custom-file-header

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值