当前位置:   article > 正文

自定义AndroidStudio中的默认Header信息_android studio创建类的默认开头

android studio创建类的默认开头

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,

  1. #set ($ORGANIZATION_NAME = "Super Awesome Company")
  2. #set ($CONTACT_EMAIL= "example@domain.com")
  3. #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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/953223
推荐阅读
相关标签
  

闽ICP备14008679号