修改 File and Code Templates

Settings –> Editor –>【File and Code Templates】
或者在右键new时选择子菜单【Edite File Templates...】
 

添加、修改文件模板 Files

–> 【Files】,可用来修改、添加新建某类型文件(比如Class、Interface、C++)时的文件模板
此文件保存位置【C:\Users\Administrator\.AndroidStudio2.3\config\fileTemplates\internal】
以下为新建Class文件的模板:
#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

#if (${IMPORT_BLOCK} != "")${IMPORT_BLOCK}
#end
#parse("File Header.java") #if (${VISIBILITY} == "PUBLIC")public #end #if (${ABSTRACT} == "TRUE")abstract #end #if (${FINAL} == "TRUE")final #end class ${NAME} #if (${SUPERCLASS} != "")extends ${SUPERCLASS} #end #if (${INTERFACES} != "")implements ${INTERFACES} #end {
}
 
注意:上面代码中的【File Header.java】文件即为下面的文件头

This is a built-in template used each time you create a new Java class, by selecting New | Java Class | Class from the popup menu in one of the project views. The template is editable. Along with Java expressions and comments, you can also use predefined variables (listed below) that will then be expanded like macros into the corresponding values. It is also possible to specify an arbitrary number of custom variables in the format ${<VARIABLE_NAME>}. In this case, before the new file is created, you will be prompted with a dialog where you can define particular values for all custom variables. Using the #parse directive, you can include templates from the Includes tab, by specifying the full name of the desired template as a parameter in quotation marks. For example: #parse("File Header.java") 
这是每次创建新的Java类时使用的内置模板,方法是选择New | Java类| 一个项目视图中的弹出菜单中的类。该模板是可编辑的。 除了Java表达式和注释外,您还可以使用预定义的变量(如下所示),然后将其扩展为宏类型到相应的值。 也可以以 $ {<VARIABLE_NAME>} 格式指定任意数量的自定义变量。 在这种情况下,在创建新文件之前,将出现一个对话框,您可以在其中定义所有自定义变量的特定值。 使用 #parse 指令,可以通过将引用中的参数指定为所需模板的全名,从 Includes 选项卡中包含模板。 例如:#parse("File Header.java") 

添加、修改文件头 Includes【重要】

–> 【Includes】,可添加、修改文件头
此文件保存位置【C:\Users\Administrator\.AndroidStudio2.3\config\fileTemplates\includes】
/**
* 作者:<a href="http://www.cnblogs.com/baiqiantao">白乾涛</a><p>
* 创建时间:${DATE} ${HOUR}:${MINUTE} <p>
* 描述:
*/
 
This is a built-in template 内置的模板. It contains a code fragment片段 that can be included into file templates (Templates tab) with the help of the #parse directive指令. The template is editable. Along with除了 static text, code and comments注释, you can also use predefined预定义的 variables变量 that will then be expanded like macros宏 into the corresponding相应的 values.
 

预定义的变量

Predefined variables will take the following values:
  • ${PACKAGE_NAME}    //name of the package in which the new file is created
  • ${USER}    //current user system login name
  • ${DATE}    //current system date
  • ${TIME}    //current system time
  • ${YEAR}    //current year
  • ${MONTH}    //current month
  • ${MONTH_NAME_SHORT}    //first 3 letters of the current month name. Example: Jan, Feb, etc.
  • ${MONTH_NAME_FULL}    //full name of the current month. Example: January, February, etc.
  • ${DAY}    //current day of the month
  • ${HOUR}    //current hour
  • ${MINUTE}    //current minute
  • ${PROJECT_NAME}    //the name of the current project
例如:【${DATE} ${HOUR}:${MINUTE}】的结果为【2017/9/20 10:28】
 

添加代码模板 Live Templates【重要】

Setting->Editor->【Live Templates】
此文件保存位置【C:\Users\Administrator\.AndroidStudio2.3\config\templates】目录下,文件名和你在AS中设置的名字一样,但是会忽略掉名字中的中文。
 
【添加步骤】
1、Setting->Editor->【Live Templates】->点击+,选择【Template Group】创建一个自定义模板组
2、选中刚刚创建的group,点击+,选择【Live Template】创建一个自定义模板
  • Abbreviation:表示这个模板的快捷方式,你敲这些【字符+回车】后,模板就自动输出了
  • Description:表示这个模板描述
  • Template text:模板的内容
3、点击下面蓝色的字"change",设置你这个快捷键在哪里生效,一般把java或XML勾上就行了
4、点击右侧的按钮"Edit variables",编辑模板信息中的变量
如我的Template text中定义了四个变量 bqt、date、name、bqt2,变量名字可以随意定义(只能是字母或数字)
  • bqt:可将鼠标定位在此位置
  • date、name:点击下三角【选择】合适的方法,可自动生成日期和类名
  • skip if defined:表示当自动生成的值不为空时,光标不停留在此方法处。建议选中
5、如上例,当我输入【快捷键+回车】后输出的内容为:
  • 焦点首先在定位的第一个方法处,即bqt处;当我输入内容后按下回车,或不输入内容直按回车
  • 焦点转移到下一个定义的方法处,即date处;当按下回车
  • 这时焦点应该会转移到name处,但因为勾选了skip if defined,且此处有自动生成内容,所以焦点移到下一方法处
  • 即转移到bqt2处,此时我再按下回车键,则焦点转移到整个模板的最后(不会添加换行符)
2017-9-21

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

 
 
 
 

附件列表

AS 代码模板 文件模板 Templates MD的更多相关文章

  1. eclipse的xml文件提示templates的模板.md

    eclipse的xml文件提示templates的模板 <?xml version="1.0" encoding="UTF-8" standalone=& ...

  2. Django学习总结之模板templates

    - django模板: templates - 模板分为两个过程: 1, 加载 : loader.get_template('xxx.html') 返回值是一个template对象 2, 渲染 : t ...

  3. ##xcode 文件模板自定义

    xcode 文件模板自定义 在使用xcode内部模板创建C++类文件时,创建出来的头文件是.hpp结尾的,但是我想用.h结尾的, 所以就网上找了下资料看能不能自定义模板,这样还可以修改文档注释.在网上 ...

  4. 【Django笔记1】-视图(views)与模板(templates)

    视图(views)与模板(templates) 1,视图(views) ​ 将接收到的数据赋值给模板(渲染),再传递给浏览器.HTML代码可以直接放在views.py(文件名可任意更换),也可以放在t ...

  5. 模板templates的使用

    目录 模板及其渲染 模板查找路径 DTL模板语法 常用的模板标签 DTL常用过滤器 模块结构优化 加载静态文件 模板及其渲染 视图函数只是直接返回文本,而在实际生产环境中其实很少这样用,因为实际的页面 ...

  6. ATL开发 ActiveX控件的 inf文件模板

    ATL开发 ActiveX控件的 inf文件模板    

  7. spring 文件模板下载多种实现方式

    针对于文件的下载,我们有很多种实现方式.业务场景是这样子的,要实现Excel文件的导入和导出功能,问题对于java的POI操作没有问题,所以实现文件的下载就相对简单,只需要从数据库取出相关的数据,针对 ...

  8. Pycharm 自定义文件模板

    Pycharm 自定义文件模板 每次新建文件都有相同的代码框架,每次重复敲浪费了程序员的寿命啊 按照下面方式自定义自己的模板:

  9. Jtester+unitils+testng:DAO单元测试文件模板自动生成

    定位 本文适合于不愿意手工编写而想自动化生成DAO单元测试的筒鞋.成果是不能照搬的,但其中的"创建模板.填充内容.自动生成"思想是可以复用的.读完本文,可以了解 Python 读取 ...

随机推荐

  1. CSU - 2058 跳一跳

    Description 冰弦非常热衷于过气微信小游戏"跳一跳",现在给出了他每次游戏时的一些信息,请你帮他计算一下每局游戏的得分. 跳一跳的游戏规则如下: 玩家操控一个小棋子,在形 ...

  2. opencv 加载 修改 保存 图像

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; /* 1 加载图像 cv::imre ...

  3. 社会主义核心价值观js代码

    效果如下: 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  4. ThinkPHP连接sqlserver,错误11001

    错误代码如下: :( 11001:[Microsoft][ODBC Driver 11 for SQL Server]TCP Provider: 不知道这样的主机. 0:[Microsoft][ODB ...

  5. Cipolla算法学习小记

    转自:http://blog.csdn.net/doyouseeman/article/details/52033204 简介 Cipolla算法是解决二次剩余强有力的工具,一个脑洞大开的算法. 认真 ...

  6. Codeforces.547C.Mike and Foam(容斥/莫比乌斯反演)

    题目链接 \(Description\) 给定n个数(\(1\leq a_i\leq 5*10^5\)),每次从这n个数中选一个,如果当前集合中没有就加入集合,有就从集合中删去.每次操作后输出集合中互 ...

  7. 【贪心】【后缀自动机】Gym - 101466E - Text Editor

    题意:给你两个串A,B,以及一个整数K,让你找到B的一个尽可能长的前缀,使得其在A串中出现的次数不小于K次. 对A串建立后缀自动机,然后把B串放在上面跑,由于每到一个结点,该结点endpos集合的大小 ...

  8. [POI2015]Pustynia

    [POI2015]Pustynia 题目大意: 给定一个长度为\(n(n\le10^5)\)的正整数序列\(a\),每个数都在\(1\)到\(10^9\)范围内,告诉你其中\(s\)个数,并给出\(m ...

  9. 拆分Cocos2dx渲染部分代码

    纹理实现 思想 这个是Cocos2dx的渲染部分的最基本的实现,被我拆分到mac上,但是并不是用的EGLContext,而是搭配glfw,还有soil第三方图形库. 实现 // // main.cpp ...

  10. Codeforces Round #353 (Div. 2) C. Money Transfers 数学

    C. Money Transfers 题目连接: http://www.codeforces.com/contest/675/problem/C Description There are n ban ...